home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 2 / AACD 2.iso / AACD / Programming / perlman / man / perlfunc.txt < prev    next >
Encoding:
Text File  |  1999-09-09  |  154.0 KB  |  3,637 lines

  1. NAME
  2.        perlfunc - Perl builtin functions
  3.  
  4. DESCRIPTION
  5.        The functions in this section can serve as terms in an
  6.        expression.  They fall into two major categories: list
  7.        operators and named unary operators.  These differ in
  8.        their precedence relationship with a following comma.
  9.        (See the precedence table in the perlop manpage.)  List
  10.        operators take more than one argument, while unary
  11.        operators can never take more than one argument.  Thus, a
  12.        comma terminates the argument of a unary operator, but
  13.        merely separates the arguments of a list operator.  A
  14.        unary operator generally provides a scalar context to its
  15.        argument, while a list operator may provide either scalar
  16.        and list contexts for its arguments.  If it does both, the
  17.        scalar arguments will be first, and the list argument will
  18.        follow.  (Note that there can only ever be one list
  19.        argument.)  For instance, splice() has three scalar
  20.        arguments followed by a list.
  21.  
  22.        In the syntax descriptions that follow, list operators
  23.        that expect a list (and provide list context for the
  24.        elements of the list) are shown with LIST as an argument.
  25.        Such a list may consist of any combination of scalar
  26.        arguments or list values; the list values will be included
  27.        in the list as if each individual element were
  28.        interpolated at that point in the list, forming a longer
  29.        single-dimensional list value.  Elements of the LIST
  30.        should be separated by commas.
  31.  
  32.        Any function in the list below may be used either with or
  33.        without parentheses around its arguments.  (The syntax
  34.        descriptions omit the parens.)  If you use the parens, the
  35.        simple (but occasionally surprising) rule is this: It
  36.        LOOKS like a function, therefore it IS a function, and
  37.        precedence doesn't matter.  Otherwise it's a list operator
  38.        or unary operator, and precedence does matter.  And
  39.        whitespace between the function and left parenthesis
  40.        doesn't count--so you need to be careful sometimes:
  41.  
  42.            print 1+2+3;        # Prints 6.
  43.            print(1+2) + 3;     # Prints 3.
  44.            print (1+2)+3;      # Also prints 3!
  45.            print +(1+2)+3;     # Prints 6.
  46.            print ((1+2)+3);    # Prints 6.
  47.  
  48.        If you run Perl with the -w switch it can warn you about
  49.        this.  For example, the third line above produces:
  50.  
  51.            print (...) interpreted as function at - line 1.
  52.            Useless use of integer addition in void context at - line 1.
  53.  
  54.        For functions that can be used in either a scalar or list
  55.        context, non-abortive failure is generally indicated in a
  56.        scalar context by returning the undefined value, and in a
  57.        list context by returning the null list.
  58.  
  59.        Remember the following rule:
  60.  
  61.                THERE IS NO GENERAL RULE FOR CONVERTING A LIST
  62.                INTO A SCALAR!
  63.  
  64.        Each operator and function decides which sort of value it
  65.        would be most appropriate to return in a scalar context.
  66.        Some operators return the length of the list that would
  67.        have been returned in a list context.  Some operators
  68.        return the first value in the list.  Some operators return
  69.        the last value in the list.  Some operators return a count
  70.        of successful operations.  In general, they do what you
  71.        want, unless you want consistency.
  72.  
  73.        Perl Functions by Category
  74.  
  75.        Here are Perl's functions (including things that look like
  76.        functions, like some of the keywords and named operators)
  77.        arranged by category.  Some functions appear in more than
  78.        one place.
  79.  
  80.        Functions for SCALARs or strings
  81.             chomp, chop, chr, crypt, hex, index, lc, lcfirst,
  82.             length, oct, ord, pack, q/STRING/, qq/STRING/,
  83.             reverse, rindex, sprintf, substr, tr///, uc, ucfirst,
  84.             y///
  85.  
  86.        Regular expressions and pattern matching
  87.             m//, pos, quotemeta, s///, split, study
  88.  
  89.        Numeric functions
  90.             abs, atan2, cos, exp, hex, int, log, oct, rand, sin,
  91.             sqrt, srand
  92.  
  93.        Functions for real @ARRAYs
  94.             pop, push, shift, splice, unshift
  95.  
  96.        Functions for list data
  97.             grep, join, map, qw/STRING/, reverse, sort, unpack
  98.  
  99.        Functions for real %HASHes
  100.             delete, each, exists, keys, values
  101.  
  102.        Input and output functions
  103.             binmode, close, closedir, dbmclose, dbmopen, die,
  104.             eof, fileno, flock, format, getc, print, printf,
  105.             read, readdir, rewinddir, seek, seekdir, select,
  106.             syscall, sysread, syswrite, tell, telldir, truncate,
  107.             warn, write
  108.  
  109.        Functions for fixed length data or records
  110.             pack, read, syscall, sysread, syswrite, unpack, vec
  111.  
  112.        Functions for filehandles, files, or directories
  113.             -X, chdir, chmod, chown, chroot, fcntl, glob, ioctl,
  114.             link, lstat, mkdir, open, opendir, readlink, rename,
  115.             rmdir, stat, symlink, umask, unlink, utime
  116.  
  117.        Keywords related to the control flow of your perl program
  118.             caller, continue, die, do, dump, eval, exit, goto,
  119.             last, next, redo, return, sub, wantarray
  120.  
  121.        Keywords related to scoping
  122.             caller, import, local, my, package, use
  123.  
  124.        Miscellaneous functions
  125.             defined, dump, eval, formline, local, my, reset,
  126.             scalar, undef, wantarray
  127.  
  128.        Functions for processes and process groups
  129.             alarm, exec, fork, getpgrp, getppid, getpriority,
  130.             kill, pipe, qx/STRING/, setpgrp, setpriority, sleep,
  131.             system, times, wait, waitpid
  132.  
  133.        Keywords related to perl modules
  134.             do, import, no, package, require, use
  135.  
  136.        Keywords related to classes and object-orientedness
  137.             bless, dbmclose, dbmopen, package, ref, tie, tied,
  138.             untie, use
  139.  
  140.        Low-level socket functions
  141.             accept, bind, connect, getpeername, getsockname,
  142.             getsockopt, listen, recv, send, setsockopt, shutdown,
  143.             socket, socketpair
  144.  
  145.        System V interprocess communication functions
  146.             msgctl, msgget, msgrcv, msgsnd, semctl, semget,
  147.             semop, shmctl, shmget, shmread, shmwrite
  148.  
  149.        Fetching user and group info
  150.             endgrent, endhostent, endnetent, endpwent, getgrent,
  151.             getgrgid, getgrnam, getlogin, getpwent, getpwnam,
  152.             getpwuid, setgrent, setpwent
  153.  
  154.        Fetching network info
  155.             endprotoent, endservent, gethostbyaddr,
  156.             gethostbyname, gethostent, getnetbyaddr,
  157.             getnetbyname, getnetent, getprotobyname,
  158.             getprotobynumber, getprotoent, getservbyname,
  159.             getservbyport, getservent, sethostent, setnetent,
  160.             setprotoent, setservent
  161.  
  162.        Time-related functions
  163.             gmtime, localtime, time, times
  164.  
  165.        Functions new in perl5
  166.             abs, bless, chomp, chr, exists, formline, glob,
  167.             import, lc, lcfirst, map, my, no, qx, qw, ref, sub*,
  168.             sysopen, tie, tied, uc, ucfirst, untie, use
  169.  
  170.             * - sub was a keyword in perl4, but in perl5 it is an
  171.             operator which can be used in expressions.
  172.  
  173.        Functions obsoleted in perl5
  174.             dbmclose, dbmopen
  175.  
  176.        Alphabetical Listing of Perl Functions
  177.  
  178.        -X FILEHANDLE
  179.  
  180.        -X EXPR
  181.  
  182.        -X      A file test, where X is one of the letters listed
  183.                below.  This unary operator takes one argument,
  184.                either a filename or a filehandle, and tests the
  185.                associated file to see if something is true about
  186.                it.  If the argument is omitted, tests $_, except
  187.                for -t, which tests STDIN.  Unless otherwise
  188.                documented, it returns 1 for TRUE and '' for
  189.                FALSE, or the undefined value if the file doesn't
  190.                exist.  Despite the funny names, precedence is the
  191.                same as any other named unary operator, and the
  192.                argument may be parenthesized like any other unary
  193.                operator.  The operator may be any of:
  194.  
  195.                    -r  File is readable by effective uid/gid.
  196.                    -w  File is writable by effective uid/gid.
  197.                    -x  File is executable by effective uid/gid.
  198.                    -o  File is owned by effective uid.
  199.  
  200.                    -R  File is readable by real uid/gid.
  201.                    -W  File is writable by real uid/gid.
  202.                    -X  File is executable by real uid/gid.
  203.                    -O  File is owned by real uid.
  204.  
  205.                    -e  File exists.
  206.                    -z  File has zero size.
  207.                    -s  File has non-zero size (returns size).
  208.  
  209.                    -f  File is a plain file.
  210.                    -d  File is a directory.
  211.                    -l  File is a symbolic link.
  212.                    -p  File is a named pipe (FIFO).
  213.                    -S  File is a socket.
  214.                    -b  File is a block special file.
  215.                    -c  File is a character special file.
  216.                    -t  Filehandle is opened to a tty.
  217.  
  218.                    -u  File has setuid bit set.
  219.                    -g  File has setgid bit set.
  220.                    -k  File has sticky bit set.
  221.  
  222.                    -T  File is a text file.
  223.                    -B  File is a binary file (opposite of -T).
  224.  
  225.                    -M  Age of file in days when script started.
  226.                    -A  Same for access time.
  227.                    -C  Same for inode change time.
  228.  
  229.                The interpretation of the file permission
  230.                operators -r, -R, -w, -W, -x and -X is based
  231.                solely on the mode of the file and the uids and
  232.                gids of the user.  There may be other reasons you
  233.                can't actually read, write or execute the file.
  234.                Also note that, for the superuser, -r, -R, -w and
  235.                -W always return 1, and -x and -X return 1 if any
  236.                execute bit is set in the mode.  Scripts run by
  237.                the superuser may thus need to do a stat() in
  238.                order to determine the actual mode of the file, or
  239.                temporarily set the uid to something else.
  240.  
  241.                Example:
  242.  
  243.                    while (<>) {
  244.                        chop;
  245.                        next unless -f $_;      # ignore specials
  246.                        ...
  247.                    }
  248.  
  249.                Note that -s/a/b/ does not do a negated
  250.                substitution.  Saying -exp($foo) still works as
  251.                expected, however--only single letters following a
  252.                minus are interpreted as file tests.
  253.  
  254.                The -T and -B switches work as follows.  The first
  255.                block or so of the file is examined for odd
  256.                characters such as strange control codes or
  257.                characters with the high bit set.  If too many odd
  258.                characters (>30%) are found, it's a -B file,
  259.                otherwise it's a -T file.  Also, any file
  260.                containing null in the first block is considered a
  261.                binary file.  If -T or -B is used on a filehandle,
  262.                the current stdio buffer is examined rather than
  263.                the first block.  Both -T and -B return TRUE on a
  264.                null file, or a file at EOF when testing a
  265.                filehandle.  Because you have to read a file to do
  266.                the -T test, on most occasions you want to use a
  267.                -f against the file first, as in next unless -f
  268.                $file && -T $file.
  269.  
  270.                If any of the file tests (or either the stat() or
  271.                lstat() operators) are given the special
  272.                filehandle consisting of a solitary underline,
  273.                then the stat structure of the previous file test
  274.                (or stat operator) is used, saving a system call.
  275.                (This doesn't work with -t, and you need to
  276.                remember that lstat() and -l will leave values in
  277.                the stat structure for the symbolic link, not the
  278.                real file.)  Example:
  279.  
  280.                    print "Can do.\n" if -r $a || -w _ || -x _;
  281.  
  282.                    stat($filename);
  283.                    print "Readable\n" if -r _;
  284.                    print "Writable\n" if -w _;
  285.                    print "Executable\n" if -x _;
  286.                    print "Setuid\n" if -u _;
  287.                    print "Setgid\n" if -g _;
  288.                    print "Sticky\n" if -k _;
  289.                    print "Text\n" if -T _;
  290.                    print "Binary\n" if -B _;
  291.  
  292.        abs VALUE
  293.                Returns the absolute value of its argument.
  294.  
  295.        accept NEWSOCKET,GENERICSOCKET
  296.                Accepts an incoming socket connect, just as the
  297.                accept(2) system call does.  Returns the packed
  298.                address if it succeeded, FALSE otherwise.  See
  299.                example in the section on Sockets: Client/Server
  300.                Communication in the perlipc manpage.
  301.  
  302.        alarm SECONDS
  303.                Arranges to have a SIGALRM delivered to this
  304.                process after the specified number of seconds have
  305.                elapsed.  (On some machines, unfortunately, the
  306.                elapsed time may be up to one second less than you
  307.                specified because of how seconds are counted.)
  308.                Only one timer may be counting at once.  Each call
  309.                disables the previous timer, and an argument of 0
  310.                may be supplied to cancel the previous timer
  311.                without starting a new one.  The returned value is
  312.                the amount of time remaining on the previous
  313.                timer.
  314.  
  315.                For delays of finer granularity than one second,
  316.                you may use Perl's syscall() interface to access
  317.                setitimer(2) if your system supports it, or else
  318.                see the select() entry elsewhere in this
  319.                documentbelow.  It is not advised to intermix
  320.                alarm() and sleep() calls.
  321.  
  322.        atan2 Y,X
  323.                Returns the arctangent of Y/X in the range -pi to
  324.                pi.
  325.  
  326.        bind SOCKET,NAME
  327.                Binds a network address to a socket, just as the
  328.                bind system call does.  Returns TRUE if it
  329.                succeeded, FALSE otherwise.  NAME should be a
  330.                packed address of the appropriate type for the
  331.                socket.  See the examples in the section on
  332.                Sockets: Client/Server Communication in the
  333.                perlipc manpage.
  334.  
  335.        binmode FILEHANDLE
  336.                Arranges for the file to be read or written in
  337.                "binary" mode in operating systems that
  338.                distinguish between binary and text files.  Files
  339.                that are not in binary mode have CR LF sequences
  340.                translated to LF on input and LF translated to CR
  341.                LF on output.  Binmode has no effect under Unix;
  342.                in DOS and similarly archaic systems, it may be
  343.                imperative--otherwise your DOS-damaged C library
  344.                may mangle your file.  The key distinction between
  345.                systems that need binmode and those that don't is
  346.                their text file formats.  Systems like Unix and
  347.                Plan9 that delimit lines with a single character,
  348.                and that encode that character in C as '\n', do
  349.                not need binmode.  The rest need it.  If
  350.                FILEHANDLE is an expression, the value is taken as
  351.                the name of the filehandle.
  352.  
  353.        bless REF,CLASSNAME
  354.  
  355.        bless REF
  356.                This function tells the referenced object (passed
  357.                as REF) that it is now an object in the CLASSNAME
  358.                package--or the current package if no CLASSNAME is
  359.                specified, which is often the case.  It returns
  360.                the reference for convenience, since a bless() is
  361.                often the last thing in a constructor.  Always use
  362.                the two-argument version if the function doing the
  363.                blessing might be inherited by a derived class.
  364.                See the perlobj manpage for more about the
  365.                blessing (and blessings) of objects.
  366.  
  367.        caller EXPR
  368.  
  369.        caller  Returns the context of the current subroutine
  370.                call.  In a scalar context, returns TRUE if there
  371.                is a caller, that is, if we're in a subroutine or
  372.                eval() or require(), and FALSE otherwise.  In a
  373.                list context, returns
  374.  
  375.                    ($package, $filename, $line) = caller;
  376.  
  377.                With EXPR, it returns some extra information that
  378.                the debugger uses to print a stack trace.  The
  379.                value of EXPR indicates how many call frames to go
  380.                back before the current one.
  381.  
  382.                    ($package, $filename, $line,
  383.                     $subroutine, $hasargs, $wantargs) = caller($i);
  384.  
  385.                Furthermore, when called from within the DB
  386.                package, caller returns more detailed information:
  387.                it sets the list variable @DB::args to be the
  388.                arguments with which that subroutine was invoked.
  389.  
  390.        chdir EXPR
  391.                Changes the working directory to EXPR, if
  392.                possible.  If EXPR is omitted, changes to home
  393.                directory.  Returns TRUE upon success, FALSE
  394.                otherwise.  See example under die().
  395.  
  396.        chmod LIST
  397.                Changes the permissions of a list of files.  The
  398.                first element of the list must be the numerical
  399.                mode, which should probably be an octal number.
  400.                Returns the number of files successfully changed.
  401.  
  402.                    $cnt = chmod 0755, 'foo', 'bar';
  403.                    chmod 0755, @executables;
  404.  
  405.        chomp VARIABLE
  406.  
  407.        chomp LIST
  408.  
  409.        chomp   This is a slightly safer version of chop (see
  410.                below).  It removes any line ending that
  411.                corresponds to the current value of $/ (also known
  412.                as $INPUT_RECORD_SEPARATOR in the English module).
  413.                It returns the number of characters removed.  It's
  414.                often used to remove the newline from the end of
  415.                an input record when you're worried that the final
  416.                record may be missing its newline.  When in
  417.                paragraph mode ($/ = ""), it removes all trailing
  418.                newlines from the string.  If VARIABLE is omitted,
  419.                it chomps $_.  Example:
  420.  
  421.                    while (<>) {
  422.                        chomp;  # avoid \n on last field
  423.                        @array = split(/:/);
  424.                        ...
  425.                    }
  426.  
  427.                You can actually chomp anything that's an lvalue,
  428.                including an assignment:
  429.  
  430.                    chomp($cwd = `pwd`);
  431.                    chomp($answer = <STDIN>);
  432.  
  433.                If you chomp a list, each element is chomped, and
  434.                the total number of characters removed is
  435.                returned.
  436.  
  437.        chop VARIABLE
  438.  
  439.        chop LIST
  440.  
  441.        chop    Chops off the last character of a string and
  442.                returns the character chopped.  It's used
  443.                primarily to remove the newline from the end of an
  444.                input record, but is much more efficient than
  445.                s/\n// because it neither scans nor copies the
  446.                string.  If VARIABLE is omitted, chops $_.
  447.                Example:
  448.  
  449.                    while (<>) {
  450.                        chop;   # avoid \n on last field
  451.                        @array = split(/:/);
  452.                        ...
  453.                    }
  454.  
  455.                You can actually chop anything that's an lvalue,
  456.                including an assignment:
  457.  
  458.                    chop($cwd = `pwd`);
  459.                    chop($answer = <STDIN>);
  460.  
  461.                If you chop a list, each element is chopped.  Only
  462.                the value of the last chop is returned.
  463.  
  464.                Note that chop returns the last character.  To
  465.                return all but the last character, use
  466.                substr($string, 0, -1).
  467.  
  468.        chown LIST
  469.                Changes the owner (and group) of a list of files.
  470.                The first two elements of the list must be the
  471.                NUMERICAL uid and gid, in that order.  Returns the
  472.                number of files successfully changed.
  473.  
  474.                    $cnt = chown $uid, $gid, 'foo', 'bar';
  475.                    chown $uid, $gid, @filenames;
  476.  
  477.                Here's an example that looks up non-numeric uids
  478.                in the passwd file:
  479.  
  480.                    print "User: ";
  481.                    chop($user = <STDIN>);
  482.                    print "Files: "
  483.                    chop($pattern = <STDIN>);
  484.  
  485.                    ($login,$pass,$uid,$gid) = getpwnam($user)
  486.                        or die "$user not in passwd file";
  487.  
  488.                    @ary = <${pattern}>;        # expand filenames
  489.                    chown $uid, $gid, @ary;
  490.  
  491.                On most systems, you are not allowed to change the
  492.                ownership of the file unless you're the superuser,
  493.                although you should be able to change the group to
  494.                any of your secondary groups.  On insecure
  495.                systems, these restrictions may be relaxed, but
  496.                this is not a portable assumption.
  497.  
  498.        chr NUMBER
  499.                Returns the character represented by that NUMBER
  500.                in the character set.  For example, chr(65) is "A"
  501.                in ASCII.
  502.  
  503.        chroot FILENAME
  504.                This function works as the system call by the same
  505.                name: it makes the named directory the new root
  506.                directory for all further pathnames that begin
  507.                with a "/" by your process and all of its
  508.                children.  (It doesn't change your current working
  509.                directory is unaffected.)  For security reasons,
  510.                this call is restricted to the superuser.  If
  511.                FILENAME is omitted, does chroot to $_.
  512.  
  513.        close FILEHANDLE
  514.                Closes the file or pipe associated with the file
  515.                handle, returning TRUE only if stdio successfully
  516.                flushes buffers and closes the system file
  517.                descriptor.  You don't have to close FILEHANDLE if
  518.                you are immediately going to do another open() on
  519.                it, since open() will close it for you.  (See
  520.                open().)  However, an explicit close on an input
  521.                file resets the line counter ($.), while the
  522.                implicit close done by open() does not.  Also,
  523.                closing a pipe will wait for the process executing
  524.                on the pipe to complete, in case you want to look
  525.                at the output of the pipe afterwards.  Closing a
  526.                pipe explicitly also puts the status value of the
  527.                command into $?.  Example:
  528.                    open(OUTPUT, '|sort >foo'); # pipe to sort
  529.                    ...                         # print stuff to output
  530.                    close OUTPUT;               # wait for sort to finish
  531.                    open(INPUT, 'foo');         # get sort's results
  532.  
  533.                FILEHANDLE may be an expression whose value gives
  534.                the real filehandle name.
  535.  
  536.        closedir DIRHANDLE
  537.                Closes a directory opened by opendir().
  538.  
  539.        connect SOCKET,NAME
  540.                Attempts to connect to a remote socket, just as
  541.                the connect system call does.  Returns TRUE if it
  542.                succeeded, FALSE otherwise.  NAME should be a
  543.                packed address of the appropriate type for the
  544.                socket.  See the examples in the section on
  545.                Sockets: Client/Server Communication in the
  546.                perlipc manpage.
  547.  
  548.        continue BLOCK
  549.                Actually a flow control statement rather than a
  550.                function.  If there is a continue BLOCK attached
  551.                to a BLOCK (typically in a while or foreach), it
  552.                is always executed just before the conditional is
  553.                about to be evaluated again, just like the third
  554.                part of a for loop in C.  Thus it can be used to
  555.                increment a loop variable, even when the loop has
  556.                been continued via the next statement (which is
  557.                similar to the C continue statement).
  558.  
  559.        cos EXPR
  560.                Returns the cosine of EXPR (expressed in radians).
  561.                If EXPR is omitted takes cosine of $_.
  562.  
  563.        crypt PLAINTEXT,SALT
  564.                Encrypts a string exactly like the crypt(3)
  565.                function in the C library (assuming that you
  566.                actually have a version there that has not been
  567.                extirpated as a potential munition).  This can
  568.                prove useful for checking the password file for
  569.                lousy passwords, amongst other things.  Only the
  570.                guys wearing white hats should do this.
  571.  
  572.                Here's an example that makes sure that whoever
  573.                runs this program knows their own password:
  574.  
  575.                    $pwd = (getpwuid($<))[1];
  576.                    $salt = substr($pwd, 0, 2);
  577.  
  578.                    system "stty -echo";
  579.                    print "Password: ";
  580.                    chop($word = <STDIN>);
  581.                    print "\n";
  582.                    system "stty echo";
  583.  
  584.                    if (crypt($word, $salt) ne $pwd) {
  585.                        die "Sorry...\n";
  586.                    } else {
  587.                        print "ok\n";
  588.                    }
  589.  
  590.                Of course, typing in your own password to whoever
  591.                asks you for it is unwise.
  592.  
  593.        dbmclose ASSOC_ARRAY
  594.                [This function has been superseded by the untie()
  595.                function.]
  596.  
  597.                Breaks the binding between a DBM file and an
  598.                associative array.
  599.  
  600.        dbmopen ASSOC,DBNAME,MODE
  601.                [This function has been superseded by the tie()
  602.                function.]
  603.  
  604.                This binds a dbm(3), ndbm(3), sdbm(3), gdbm(), or
  605.                Berkeley DB file to an associative array.  ASSOC
  606.                is the name of the associative array.  (Unlike
  607.                normal open, the first argument is NOT a
  608.                filehandle, even though it looks like one).
  609.                DBNAME is the name of the database (without the
  610.                .dir or .pag extension if any).  If the database
  611.                does not exist, it is created with protection
  612.                specified by MODE (as modified by the umask()).
  613.                If your system only supports the older DBM
  614.                functions, you may perform only one dbmopen() in
  615.                your program.  In older versions of Perl, if your
  616.                system had neither DBM nor ndbm, calling dbmopen()
  617.                produced a fatal error; it now falls back to
  618.                sdbm(3).
  619.  
  620.                If you don't have write access to the DBM file,
  621.                you can only read associative array variables, not
  622.                set them.  If you want to test whether you can
  623.                write, either use file tests or try setting a
  624.                dummy array entry inside an eval(), which will
  625.                trap the error.
  626.  
  627.                Note that functions such as keys() and values()
  628.                may return huge array values when used on large
  629.                DBM files.  You may prefer to use the each()
  630.                function to iterate over large DBM files.
  631.                Example:
  632.                    # print out history file offsets
  633.                    dbmopen(%HIST,'/usr/lib/news/history',0666);
  634.                    while (($key,$val) = each %HIST) {
  635.                        print $key, ' = ', unpack('L',$val), "\n";
  636.                    }
  637.                    dbmclose(%HIST);
  638.  
  639.                See also the AnyDBM_File manpage for a more
  640.                general description of the pros and cons of the
  641.                various dbm apparoches, as well as the DB_File
  642.                manpage for a particularly rich implementation.
  643.  
  644.        defined EXPR
  645.                Returns a boolean value saying whether EXPR has a
  646.                real value or not.  Many operations return the
  647.                undefined value under exceptional conditions, such
  648.                as end of file, uninitialized variable, system
  649.                error and such.  This function allows you to
  650.                distinguish between an undefined null scalar and a
  651.                defined null scalar with operations that might
  652.                return a real null string, such as referencing
  653.                elements of an array.  You may also check to see
  654.                if arrays or subroutines exist.  Use of defined on
  655.                predefined variables is not guaranteed to produce
  656.                intuitive results.
  657.  
  658.                When used on a hash array element, it tells you
  659.                whether the value is defined, not whether the key
  660.                exists in the hash.  Use exists() for that.
  661.  
  662.                Examples:
  663.  
  664.                    print if defined $switch{'D'};
  665.                    print "$val\n" while defined($val = pop(@ary));
  666.                    die "Can't readlink $sym: $!"
  667.                        unless defined($value = readlink $sym);
  668.                    eval '@foo = ()' if defined(@foo);
  669.                    die "No XYZ package defined" unless defined %_XYZ;
  670.                    sub foo { defined &$bar ? &$bar(@_) : die "No bar"; }
  671.  
  672.                See also undef().
  673.  
  674.                Note: many folks tend to overuse defined(), and
  675.                then are surprised to discover that the number 0
  676.                and the null string are, in fact, defined
  677.                concepts.  For example, if you say
  678.  
  679.                    "ab" =~ /a(.*)b/;
  680.  
  681.                the pattern match succeeds, and $1 is defined,
  682.                despite the fact that it matched "nothing".  But
  683.                it didn't really match nothing--rather, it matched
  684.                something that happened to be 0 characters long.
  685.                This is all very above-board and honest.  When a
  686.                function returns an undefined value, it's an
  687.                admission that it couldn't give you an honest
  688.                answer.  So you should only use defined() when
  689.                you're questioning the integrity of what you're
  690.                trying to do.  At other times, a simple comparison
  691.                to 0 or "" is what you want.
  692.  
  693.        delete EXPR
  694.                Deletes the specified value from its hash array.
  695.                Returns the deleted value, or the undefined value
  696.                if nothing was deleted.  Deleting from $ENV{}
  697.                modifies the environment.  Deleting from an array
  698.                tied to a DBM file deletes the entry from the DBM
  699.                file.  (But deleting from a tie()d hash doesn't
  700.                necessarily return anything.)
  701.  
  702.                The following deletes all the values of an
  703.                associative array:
  704.  
  705.                    foreach $key (keys %ARRAY) {
  706.                        delete $ARRAY{$key};
  707.                    }
  708.  
  709.                (But it would be faster to use the undef()
  710.                command.)  Note that the EXPR can be arbitrarily
  711.                complicated as long as the final operation is a
  712.                hash key lookup:
  713.  
  714.                    delete $ref->[$x][$y]{$key};
  715.  
  716.        die LIST
  717.                Outside of an eval(), prints the value of LIST to
  718.                STDERR and exits with the current value of $!
  719.                (errno).  If $! is 0, exits with the value of ($?
  720.                >> 8) (backtick `command` status).  If ($? >> 8)
  721.                is 0, exits with 255.  Inside an eval(), the error
  722.                message is stuffed into $@, and the eval() is
  723.                terminated with the undefined value; this makes
  724.                die() the way to raise an exception.
  725.  
  726.                Equivalent examples:
  727.  
  728.                    die "Can't cd to spool: $!\n" unless chdir '/usr/spool/news';
  729.                    chdir '/usr/spool/news' or die "Can't cd to spool: $!\n"
  730.  
  731.                If the value of EXPR does not end in a newline,
  732.                the current script line number and input line
  733.                number (if any) are also printed, and a newline is
  734.                supplied.  Hint: sometimes appending ", stopped"
  735.                to your message will cause it to make better sense
  736.                when the string "at foo line 123" is appended.
  737.                Suppose you are running script "canasta".
  738.  
  739.                    die "/etc/games is no good";
  740.                    die "/etc/games is no good, stopped";
  741.  
  742.                produce, respectively
  743.  
  744.                    /etc/games is no good at canasta line 123.
  745.                    /etc/games is no good, stopped at canasta line 123.
  746.  
  747.                See also exit() and warn().
  748.  
  749.        do BLOCK
  750.                Not really a function.  Returns the value of the
  751.                last command in the sequence of commands indicated
  752.                by BLOCK.  When modified by a loop modifier,
  753.                executes the BLOCK once before testing the loop
  754.                condition.  (On other statements the loop
  755.                modifiers test the conditional first.)
  756.  
  757.        do SUBROUTINE(LIST)
  758.                A deprecated form of subroutine call.  See the
  759.                perlsub manpage.
  760.  
  761.        do EXPR Uses the value of EXPR as a filename and executes
  762.                the contents of the file as a Perl script.  Its
  763.                primary use is to include subroutines from a Perl
  764.                subroutine library.
  765.  
  766.                    do 'stat.pl';
  767.  
  768.                is just like
  769.  
  770.                    eval `cat stat.pl`;
  771.  
  772.                except that it's more efficient, more concise,
  773.                keeps track of the current filename for error
  774.                messages, and searches all the -I libraries if the
  775.                file isn't in the current directory (see also the
  776.                @INC array in the section on Predefined Names in
  777.                the perlvar manpage).  It's the same, however, in
  778.                that it does reparse the file every time you call
  779.                it, so you probably don't want to do this inside a
  780.                loop.
  781.  
  782.                Note that inclusion of library modules is better
  783.                done with the use() and require() operators, which
  784.                also do error checking and raise an exception if
  785.                there's a problem.
  786.  
  787.        dump LABEL
  788.                This causes an immediate core dump.  Primarily
  789.                this is so that you can use the undump program to
  790.                turn your core dump into an executable binary
  791.                after having initialized all your variables at the
  792.                beginning of the program.  When the new binary is
  793.                executed it will begin by executing a goto LABEL
  794.                (with all the restrictions that goto suffers).
  795.                Think of it as a goto with an intervening core
  796.                dump and reincarnation.  If LABEL is omitted,
  797.                restarts the program from the top.  WARNING: any
  798.                files opened at the time of the dump will NOT be
  799.                open any more when the program is reincarnated,
  800.                with possible resulting confusion on the part of
  801.                Perl.  See also -u option in the perlrun manpage.
  802.  
  803.                Example:
  804.  
  805.                    #!/usr/bin/perl
  806.                    require 'getopt.pl';
  807.                    require 'stat.pl';
  808.                    %days = (
  809.                        'Sun' => 1,
  810.                        'Mon' => 2,
  811.                        'Tue' => 3,
  812.                        'Wed' => 4,
  813.                        'Thu' => 5,
  814.                        'Fri' => 6,
  815.                        'Sat' => 7,
  816.                    );
  817.  
  818.                    dump QUICKSTART if $ARGV[0] eq '-d';
  819.  
  820.                    QUICKSTART:
  821.                    Getopt('f');
  822.  
  823.        each ASSOC_ARRAY
  824.                Returns a 2-element array consisting of the key
  825.                and value for the next value of an associative
  826.                array, so that you can iterate over it.  Entries
  827.                are returned in an apparently random order.  When
  828.                the array is entirely read, a null array is
  829.                returned (which when assigned produces a FALSE (0)
  830.                value).  The next call to each() after that will
  831.                start iterating again.  The iterator can be reset
  832.                only by reading all the elements from the array.
  833.                You should not add elements to an array while
  834.                you're iterating over it.  There is a single
  835.                iterator for each associative array, shared by all
  836.                each(), keys() and values() function calls in the
  837.                program.  The following prints out your
  838.                environment like the printenv(1) program, only in
  839.                a different order:
  840.  
  841.                    while (($key,$value) = each %ENV) {
  842.                        print "$key=$value\n";
  843.                    }
  844.  
  845.                See also keys() and values().
  846.        eof FILEHANDLE
  847.  
  848.        eof ()
  849.  
  850.        eof     Returns 1 if the next read on FILEHANDLE will
  851.                return end of file, or if FILEHANDLE is not open.
  852.                FILEHANDLE may be an expression whose value gives
  853.                the real filehandle name.  (Note that this
  854.                function actually reads a character and then
  855.                ungetc()s it, so it is not very useful in an
  856.                interactive context.)  Do not read from a terminal
  857.                file (or call eof(FILEHANDLE) on it) after end-of-
  858.                file is reached.  Filetypes such as terminals may
  859.                lose the end-of-file condition if you do.
  860.  
  861.                An eof without an argument uses the last file read
  862.                as argument.  Empty parentheses () may be used to
  863.                indicate the pseudofile formed of the files listed
  864.                on the command line, i.e.  eof() is reasonable to
  865.                use inside a while (<>) loop to detect the end of
  866.                only the last file.  Use eof(ARGV) or eof without
  867.                the parentheses to test EACH file in a while (<>)
  868.                loop.  Examples:
  869.  
  870.                    # reset line numbering on each input file
  871.                    while (<>) {
  872.                        print "$.\t$_";
  873.                        close(ARGV) if (eof);   # Not eof().
  874.                    }
  875.  
  876.                    # insert dashes just before last line of last file
  877.                    while (<>) {
  878.                        if (eof()) {
  879.                            print "--------------\n";
  880.                            close(ARGV);        # close or break; is needed if we
  881.                                                # are reading from the terminal
  882.                        }
  883.                        print;
  884.                    }
  885.  
  886.                Practical hint: you almost never need to use eof
  887.                in Perl, because the input operators return undef
  888.                when they run out of data.
  889.  
  890.        eval EXPR
  891.  
  892.        eval BLOCK
  893.                EXPR is parsed and executed as if it were a little
  894.                Perl program.  It is executed in the context of
  895.                the current Perl program, so that any variable
  896.                settings, subroutine or format definitions remain
  897.                afterwards.  The value returned is the value of
  898.                the last expression evaluated, or a return
  899.                statement may be used, just as with subroutines.
  900.                If there is a syntax error or runtime error, or a
  901.                die() statement is executed, an undefined value is
  902.                returned by eval(), and $@ is set to the error
  903.                message.  If there was no error, $@ is guaranteed
  904.                to be a null string.  If EXPR is omitted,
  905.                evaluates $_.  The final semicolon, if any, may be
  906.                omitted from the expression.
  907.  
  908.                Note that, since eval() traps otherwise-fatal
  909.                errors, it is useful for determining whether a
  910.                particular feature (such as socket() or symlink())
  911.                is implemented.  It is also Perl's exception
  912.                trapping mechanism, where the die operator is used
  913.                to raise exceptions.
  914.  
  915.                If the code to be executed doesn't vary, you may
  916.                use the eval-BLOCK form to trap run-time errors
  917.                without incurring the penalty of recompiling each
  918.                time.  The error, if any, is still returned in $@.
  919.                Examples:
  920.  
  921.                    # make divide-by-zero non-fatal
  922.                    eval { $answer = $a / $b; }; warn $@ if $@;
  923.  
  924.                    # same thing, but less efficient
  925.                    eval '$answer = $a / $b'; warn $@ if $@;
  926.  
  927.                    # a compile-time error
  928.                    eval { $answer = };
  929.  
  930.                    # a run-time error
  931.                    eval '$answer =';   # sets $@
  932.  
  933.                With an eval(), you should be especially careful
  934.                to remember what's being looked at when:
  935.  
  936.                    eval $x;            # CASE 1
  937.                    eval "$x";          # CASE 2
  938.  
  939.                    eval '$x';          # CASE 3
  940.                    eval { $x };        # CASE 4
  941.  
  942.                    eval "\$$x++"       # CASE 5
  943.                    $$x++;              # CASE 6
  944.  
  945.                Cases 1 and 2 above behave identically: they run
  946.                the code contained in the variable $x.  (Although
  947.                case 2 has misleading double quotes making the
  948.                reader wonder what else might be happening
  949.                (nothing is).) Cases 3 and 4 likewise behave in
  950.                the same way: they run the code <$x>, which does
  951.                nothing at all.  (Case 4 is preferred for purely
  952.                visual reasons.) Case 5 is a place where normally
  953.                you WOULD like to use double quotes, except that
  954.                in that particular situation, you can just use
  955.                symbolic references instead, as in case 6.
  956.  
  957.        exec LIST
  958.                The exec() function executes a system command AND
  959.                NEVER RETURNS.  Use the system() function if you
  960.                want it to return.
  961.  
  962.                If there is more than one argument in LIST, or if
  963.                LIST is an array with more than one value, calls
  964.                execvp(3) with the arguments in LIST.  If there is
  965.                only one scalar argument, the argument is checked
  966.                for shell metacharacters.  If there are any, the
  967.                entire argument is passed to /bin/sh -c for
  968.                parsing.  If there are none, the argument is split
  969.                into words and passed directly to execvp(), which
  970.                is more efficient.  Note: exec() and system() do
  971.                not flush your output buffer, so you may need to
  972.                set $| to avoid lost output.  Examples:
  973.  
  974.                    exec '/bin/echo', 'Your arguments are: ', @ARGV;
  975.                    exec "sort $outfile | uniq";
  976.  
  977.                If you don't really want to execute the first
  978.                argument, but want to lie to the program you are
  979.                executing about its own name, you can specify the
  980.                program you actually want to run as an "indirect
  981.                object" (without a comma) in front of the LIST.
  982.                (This always forces interpretation of the LIST as
  983.                a multi-valued list, even if there is only a
  984.                single scalar in the list.)  Example:
  985.  
  986.                    $shell = '/bin/csh';
  987.                    exec $shell '-sh';          # pretend it's a login shell
  988.  
  989.                or, more directly,
  990.  
  991.                    exec {'/bin/csh'} '-sh';    # pretend it's a login shell
  992.  
  993.        exists EXPR
  994.                Returns TRUE if the specified hash key exists in
  995.                its hash array, even if the corresponding value is
  996.                undefined.
  997.  
  998.                    print "Exists\n" if exists $array{$key};
  999.                    print "Defined\n" if defined $array{$key};
  1000.                    print "True\n" if $array{$key};
  1001.  
  1002.                A hash element can only be TRUE if it's defined,
  1003.                and defined if it exists, but the reverse doesn't
  1004.                necessarily hold true.
  1005.  
  1006.                Note that the EXPR can be arbitrarily complicated
  1007.                as long as the final operation is a hash key
  1008.                lookup:
  1009.  
  1010.                    if (exists $ref->[$x][$y]{$key}) { ... }
  1011.  
  1012.        exit EXPR
  1013.                Evaluates EXPR and exits immediately with that
  1014.                value.  (Actually, it calls any defined END
  1015.                routines first, but the END routines may not abort
  1016.                the exit.  Likewise any object destructors that
  1017.                need to be called are called before exit.)
  1018.                Example:
  1019.  
  1020.                    $ans = <STDIN>;
  1021.                    exit 0 if $ans =~ /^[Xx]/;
  1022.  
  1023.                See also die().  If EXPR is omitted, exits with 0
  1024.                status.
  1025.  
  1026.        exp EXPR
  1027.                Returns e (the natural logarithm base) to the
  1028.                power of EXPR.  If EXPR is omitted, gives exp($_).
  1029.  
  1030.        fcntl FILEHANDLE,FUNCTION,SCALAR
  1031.                Implements the fcntl(2) function.  You'll probably
  1032.                have to say
  1033.  
  1034.                    use Fcntl;
  1035.  
  1036.                first to get the correct function definitions.
  1037.                Argument processing and value return works just
  1038.                like ioctl() below.  Note that fcntl() will
  1039.                produce a fatal error if used on a machine that
  1040.                doesn't implement fcntl(2).  For example:
  1041.  
  1042.                    use Fcntl;
  1043.                    fcntl($filehandle, F_GETLK, $packed_return_buffer);
  1044.  
  1045.        fileno FILEHANDLE
  1046.                Returns the file descriptor for a filehandle.
  1047.                This is useful for constructing bitmaps for
  1048.                select().  If FILEHANDLE is an expression, the
  1049.                value is taken as the name of the filehandle.
  1050.  
  1051.        flock FILEHANDLE,OPERATION
  1052.                Calls flock(2) on FILEHANDLE.  See the flock(2)
  1053.                manpage for definition of OPERATION.  Returns TRUE
  1054.                for success, FALSE on failure.  Will produce a
  1055.                fatal error if used on a machine that doesn't
  1056.                implement either flock(2) or fcntl(2). The
  1057.                fcntl(2) system call will be automatically used if
  1058.                flock(2) is missing from your system.  This makes
  1059.                flock() the portable file locking strategy,
  1060.                although it will only lock entire files, not
  1061.                records.  Note also that some versions of flock()
  1062.                cannot lock things over the network; you would
  1063.                need to use the more system-specific fcntl() for
  1064.                that.
  1065.  
  1066.                Here's a mailbox appender for BSD systems.
  1067.  
  1068.                    $LOCK_SH = 1;
  1069.                    $LOCK_EX = 2;
  1070.                    $LOCK_NB = 4;
  1071.                    $LOCK_UN = 8;
  1072.  
  1073.                    sub lock {
  1074.                        flock(MBOX,$LOCK_EX);
  1075.                        # and, in case someone appended
  1076.                        # while we were waiting...
  1077.                        seek(MBOX, 0, 2);
  1078.                    }
  1079.  
  1080.                    sub unlock {
  1081.                        flock(MBOX,$LOCK_UN);
  1082.                    }
  1083.  
  1084.                    open(MBOX, ">>/usr/spool/mail/$ENV{'USER'}")
  1085.                            or die "Can't open mailbox: $!";
  1086.  
  1087.                    lock();
  1088.                    print MBOX $msg,"\n\n";
  1089.                    unlock();
  1090.  
  1091.                See also the DB_File manpage for other flock()
  1092.                examples.
  1093.  
  1094.        fork    Does a fork(2) system call.  Returns the child pid
  1095.                to the parent process and 0 to the child process,
  1096.                or undef if the fork is unsuccessful.  Note:
  1097.                unflushed buffers remain unflushed in both
  1098.                processes, which means you may need to set $|
  1099.                ($AUTOFLUSH in English) or call the autoflush()
  1100.                FileHandle method to avoid duplicate output.
  1101.  
  1102.                If you fork() without ever waiting on your
  1103.                children, you will accumulate zombies:
  1104.  
  1105.                    $SIG{CHLD} = sub { wait };
  1106.  
  1107.                There's also the double-fork trick (error checking
  1108.                on fork() returns omitted);
  1109.  
  1110.                    unless ($pid = fork) {
  1111.                        unless (fork) {
  1112.                            exec "what you really wanna do";
  1113.                            die "no exec";
  1114.                            # ... or ...
  1115.                            ## (some_perl_code_here)
  1116.                            exit 0;
  1117.                        }
  1118.                        exit 0;
  1119.                    }
  1120.                    waitpid($pid,0);
  1121.  
  1122.                See also the perlipc manpage for more examples of
  1123.                forking and reaping moribund children.
  1124.  
  1125.        format  Declare a picture format with use by the write()
  1126.                function.  For example:
  1127.  
  1128.                    format Something =
  1129.                        Test: @<<<<<<<< @||||| @>>>>>
  1130.                              $str,     $%,    '$' . int($num)
  1131.                    .
  1132.  
  1133.                    $str = "widget";
  1134.                    $num = $cost/$quantiy;
  1135.                    $~ = 'Something';
  1136.                    write;
  1137.  
  1138.                See the perlform manpage for many details and
  1139.                examples.
  1140.  
  1141.        formline PICTURE, LIST
  1142.                This is an internal function used by formats,
  1143.                though you may call it too.  It formats (see the
  1144.                perlform manpage) a list of values according to
  1145.                the contents of PICTURE, placing the output into
  1146.                the format output accumulator, $^A (or
  1147.                $ACCUMULATOR in English).  Eventually, when a
  1148.                write() is done, the contents of $^A are written
  1149.                to some filehandle, but you could also read $^A
  1150.                yourself and then set $^A back to "".  Note that a
  1151.                format typically does one formline() per line of
  1152.                form, but the formline() function itself doesn't
  1153.                care how many newlines are embedded in the
  1154.                PICTURE.  This means that the ~ and ~~ tokens will
  1155.                treat the entire PICTURE as a single line.  You
  1156.                may therefore need to use multiple formlines to
  1157.                implement a single record format, just like the
  1158.                format compiler.
  1159.  
  1160.                Be careful if you put double quotes around the
  1161.                picture, since an "@" character may be taken to
  1162.                mean the beginning of an array name.  formline()
  1163.                always returns TRUE.  See the perlform manpage for
  1164.                other examples.
  1165.  
  1166.        getc FILEHANDLE
  1167.  
  1168.        getc    Returns the next character from the input file
  1169.                attached to FILEHANDLE, or a null string at end of
  1170.                file.  If FILEHANDLE is omitted, reads from STDIN.
  1171.                This is not particularly efficient.  It cannot be
  1172.                used to get unbuffered single-characters, however.
  1173.                For that, try something more like:
  1174.  
  1175.                    if ($BSD_STYLE) {
  1176.                        system "stty cbreak </dev/tty >/dev/tty 2>&1";
  1177.                    }
  1178.                    else {
  1179.                        system "stty", '-icanon', 'eol', "\001";
  1180.                    }
  1181.  
  1182.                    $key = getc(STDIN);
  1183.  
  1184.                    if ($BSD_STYLE) {
  1185.                        system "stty -cbreak </dev/tty >/dev/tty 2>&1";
  1186.                    }
  1187.                    else {
  1188.                        system "stty", 'icanon', 'eol', '^@'; # ascii null
  1189.                    }
  1190.                    print "\n";
  1191.  
  1192.                Determination of whether to whether $BSD_STYLE
  1193.                should be set is left as an exercise to the
  1194.                reader.
  1195.  
  1196.                See also the Term::ReadKey module from your
  1197.                nearest CPAN site; details on CPAN can be found on
  1198.                the CPAN entry in the perlmod manpage
  1199.  
  1200.        getlogin
  1201.                Returns the current login from /etc/utmp, if any.
  1202.                If null, use getpwuid().
  1203.  
  1204.                    $login = getlogin || (getpwuid($<))[0] || "Kilroy";
  1205.  
  1206.                Do not consider getlogin() for authorentication:
  1207.                it is not as secure as getpwuid().
  1208.  
  1209.        getpeername SOCKET
  1210.                Returns the packed sockaddr address of other end
  1211.                of the SOCKET connection.
  1212.  
  1213.                    use Socket;
  1214.                    $hersockaddr    = getpeername(SOCK);
  1215.                    ($port, $iaddr) = unpack_sockaddr_in($hersockaddr);
  1216.                    $herhostname    = gethostbyaddr($iaddr, AF_INET);
  1217.                    $herstraddr     = inet_ntoa($iaddr);
  1218.        getpgrp PID
  1219.                Returns the current process group for the
  1220.                specified PID, 0 for the current process.  Will
  1221.                raise an exception if used on a machine that
  1222.                doesn't implement getpgrp(2).  If PID is omitted,
  1223.                returns process group of current process.
  1224.  
  1225.        getppid Returns the process id of the parent process.
  1226.  
  1227.        getpriority WHICH,WHO
  1228.                Returns the current priority for a process, a
  1229.                process group, or a user.  (See the getpriority(2)
  1230.                manpage.)  Will raise a fatal exception if used on
  1231.                a machine that doesn't implement getpriority(2).
  1232.  
  1233.        getpwnam NAME
  1234.  
  1235.        getgrnam NAME
  1236.  
  1237.        gethostbyname NAME
  1238.  
  1239.        getnetbyname NAME
  1240.  
  1241.        getprotobyname NAME
  1242.  
  1243.        getpwuid UID
  1244.  
  1245.        getgrgid GID
  1246.  
  1247.        getservbyname NAME,PROTO
  1248.  
  1249.        gethostbyaddr ADDR,ADDRTYPE
  1250.  
  1251.        getnetbyaddr ADDR,ADDRTYPE
  1252.  
  1253.        getprotobynumber NUMBER
  1254.  
  1255.        getservbyport PORT,PROTO
  1256.  
  1257.        getpwent
  1258.  
  1259.        getgrent
  1260.  
  1261.        gethostent
  1262.  
  1263.        getnetent
  1264.  
  1265.        getprotoent
  1266.  
  1267.        getservent
  1268.  
  1269.        setpwent
  1270.  
  1271.        setgrent
  1272.  
  1273.        sethostent STAYOPEN
  1274.  
  1275.        setnetent STAYOPEN
  1276.  
  1277.        setprotoent STAYOPEN
  1278.  
  1279.        setservent STAYOPEN
  1280.  
  1281.        endpwent
  1282.  
  1283.        endgrent
  1284.  
  1285.        endhostent
  1286.  
  1287.        endnetent
  1288.  
  1289.        endprotoent
  1290.  
  1291.        endservent
  1292.                These routines perform the same functions as their
  1293.                counterparts in the system library.  Within a list
  1294.                context, the return values from the various get
  1295.                routines are as follows:
  1296.  
  1297.                    ($name,$passwd,$uid,$gid,
  1298.                       $quota,$comment,$gcos,$dir,$shell) = getpw*
  1299.                    ($name,$passwd,$gid,$members) = getgr*
  1300.                    ($name,$aliases,$addrtype,$length,@addrs) = gethost*
  1301.                    ($name,$aliases,$addrtype,$net) = getnet*
  1302.                    ($name,$aliases,$proto) = getproto*
  1303.                    ($name,$aliases,$port,$proto) = getserv*
  1304.  
  1305.                (If the entry doesn't exist you get a null list.)
  1306.  
  1307.                Within a scalar context, you get the name, unless
  1308.                the function was a lookup by name, in which case
  1309.                you get the other thing, whatever it is.  (If the
  1310.                entry doesn't exist you get the undefined value.)
  1311.                For example:
  1312.  
  1313.                    $uid = getpwnam
  1314.                    $name = getpwuid
  1315.                    $name = getpwent
  1316.                    $gid = getgrnam
  1317.                    $name = getgrgid
  1318.                    $name = getgrent
  1319.                    etc.
  1320.  
  1321.                The $members value returned by getgr*() is a space
  1322.                separated list of the login names of the members
  1323.                of the group.
  1324.  
  1325.                For the gethost*() functions, if the h_errno
  1326.                variable is supported in C, it will be returned to
  1327.                you via $? if the function call fails.  The @addrs
  1328.                value returned by a successful call is a list of
  1329.                the raw addresses returned by the corresponding
  1330.                system library call.  In the Internet domain, each
  1331.                address is four bytes long and you can unpack it
  1332.                by saying something like:
  1333.  
  1334.                    ($a,$b,$c,$d) = unpack('C4',$addr[0]);
  1335.  
  1336.        getsockname SOCKET
  1337.                Returns the packed sockaddr address of this end of
  1338.                the SOCKET connection.
  1339.  
  1340.                    use Socket;
  1341.                    $mysockaddr = getsockname(SOCK);
  1342.                    ($port, $myaddr) = unpack_sockaddr_in($mysockaddr);
  1343.  
  1344.        getsockopt SOCKET,LEVEL,OPTNAME
  1345.                Returns the socket option requested, or undefined
  1346.                if there is an error.
  1347.  
  1348.        glob EXPR
  1349.                Returns the value of EXPR with filename expansions
  1350.                such as a shell would do.  This is the internal
  1351.                function implementing the <*.*> operator, except
  1352.                it's easier to use.
  1353.  
  1354.        gmtime EXPR
  1355.                Converts a time as returned by the time function
  1356.                to a 9-element array with the time localized for
  1357.                the standard Greenwich timezone.  Typically used
  1358.                as follows:
  1359.  
  1360.                    ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
  1361.                                                            gmtime(time);
  1362.  
  1363.                All array elements are numeric, and come straight
  1364.                out of a struct tm.  In particular this means that
  1365.                $mon has the range 0..11 and $wday has the range
  1366.                0..6.  If EXPR is omitted, does gmtime(time()).
  1367.  
  1368.        goto LABEL
  1369.  
  1370.        goto EXPR
  1371.  
  1372.        goto &NAME
  1373.                The goto-LABEL form finds the statement labeled
  1374.                with LABEL and resumes execution there.  It may
  1375.                not be used to go into any construct that requires
  1376.                initialization, such as a subroutine or a foreach
  1377.                loop.  It also can't be used to go into a
  1378.                construct that is optimized away.  It can be used
  1379.                to go almost anywhere else within the dynamic
  1380.                scope, including out of subroutines, but it's
  1381.                usually better to use some other construct such as
  1382.                last or die.  The author of Perl has never felt
  1383.                the need to use this form of goto (in Perl, that
  1384.                is--C is another matter).
  1385.  
  1386.                The goto-EXPR form expects a label name, whose
  1387.                scope will be resolved dynamically.  This allows
  1388.                for computed gotos per FORTRAN, but isn't
  1389.                necessarily recommended if you're optimizing for
  1390.                maintainability:
  1391.  
  1392.                    goto ("FOO", "BAR", "GLARCH")[$i];
  1393.  
  1394.                The goto-&NAME form is highly magical, and
  1395.                substitutes a call to the named subroutine for the
  1396.                currently running subroutine.  This is used by
  1397.                AUTOLOAD subroutines that wish to load another
  1398.                subroutine and then pretend that the other
  1399.                subroutine had been called in the first place
  1400.                (except that any modifications to @_ in the
  1401.                current subroutine are propagated to the other
  1402.                subroutine.)  After the goto, not even caller()
  1403.                will be able to tell that this routine was called
  1404.                first.
  1405.  
  1406.        grep BLOCK LIST
  1407.  
  1408.        grep EXPR,LIST
  1409.                Evaluates the BLOCK or EXPR for each element of
  1410.                LIST (locally setting $_ to each element) and
  1411.                returns the list value consisting of those
  1412.                elements for which the expression evaluated to
  1413.                TRUE.  In a scalar context, returns the number of
  1414.                times the expression was TRUE.
  1415.  
  1416.                    @foo = grep(!/^#/, @bar);    # weed out comments
  1417.  
  1418.                or equivalently,
  1419.  
  1420.                    @foo = grep {!/^#/} @bar;    # weed out comments
  1421.  
  1422.                Note that, since $_ is a reference into the list
  1423.                value, it can be used to modify the elements of
  1424.                the array.  While this is useful and supported, it
  1425.                can cause bizarre results if the LIST is not a
  1426.                named array.
  1427.  
  1428.        hex EXPR
  1429.                Interprets EXPR as a hex string and returns the
  1430.                corresponding decimal value.  (To convert strings
  1431.                that might start with 0 or 0x see oct().)  If EXPR
  1432.                is omitted, uses $_.
  1433.  
  1434.        import  There is no built-in import() function.  It is
  1435.                merely an ordinary method (subroutine) defined (or
  1436.                inherited) by modules that wish to export names to
  1437.                another module.  The use() function calls the
  1438.                import() method for the package used.  See also
  1439.                the use entry elsewhere in this documentthe
  1440.                perlmod manpage, and the Exporter manpage.
  1441.  
  1442.        index STR,SUBSTR,POSITION
  1443.  
  1444.        index STR,SUBSTR
  1445.                Returns the position of the first occurrence of
  1446.                SUBSTR in STR at or after POSITION.  If POSITION
  1447.                is omitted, starts searching from the beginning of
  1448.                the string.  The return value is based at 0 (or
  1449.                whatever you've set the $[ variable to--but don't
  1450.                do that).  If the substring is not found, returns
  1451.                one less than the base, ordinarily -1.
  1452.  
  1453.        int EXPR
  1454.                Returns the integer portion of EXPR.  If EXPR is
  1455.                omitted, uses $_.
  1456.  
  1457.        ioctl FILEHANDLE,FUNCTION,SCALAR
  1458.                Implements the ioctl(2) function.  You'll probably
  1459.                have to say
  1460.  
  1461.                    require "ioctl.ph"; # probably in /usr/local/lib/perl/ioctl.ph
  1462.  
  1463.                first to get the correct function definitions.  If
  1464.                ioctl.ph doesn't exist or doesn't have the correct
  1465.                definitions you'll have to roll your own, based on
  1466.                your C header files such as <sys/ioctl.h>.  (There
  1467.                is a Perl script called h2ph that comes with the
  1468.                Perl kit which may help you in this, but it's non-
  1469.                trivial.)  SCALAR will be read and/or written
  1470.                depending on the FUNCTION--a pointer to the string
  1471.                value of SCALAR will be passed as the third
  1472.                argument of the actual ioctl call.  (If SCALAR has
  1473.                no string value but does have a numeric value,
  1474.                that value will be passed rather than a pointer to
  1475.                the string value.  To guarantee this to be TRUE,
  1476.                add a 0 to the scalar before using it.)  The
  1477.                pack() and unpack() functions are useful for
  1478.                manipulating the values of structures used by
  1479.                ioctl().  The following example sets the erase
  1480.                character to DEL.
  1481.  
  1482.                    require 'ioctl.ph';
  1483.                    $getp = &TIOCGETP;
  1484.                    die "NO TIOCGETP" if $@ || !$getp;
  1485.                    $sgttyb_t = "ccccs";                # 4 chars and a short
  1486.                    if (ioctl(STDIN,$getp,$sgttyb)) {
  1487.                        @ary = unpack($sgttyb_t,$sgttyb);
  1488.                        $ary[2] = 127;
  1489.                        $sgttyb = pack($sgttyb_t,@ary);
  1490.                        ioctl(STDIN,&TIOCSETP,$sgttyb)
  1491.                            || die "Can't ioctl: $!";
  1492.                    }
  1493.  
  1494.                The return value of ioctl (and fcntl) is as
  1495.                follows:
  1496.  
  1497.                        if OS returns:          then Perl returns:
  1498.                            -1                    undefined value
  1499.                             0                  string "0 but true"
  1500.                        anything else               that number
  1501.  
  1502.                Thus Perl returns TRUE on success and FALSE on
  1503.                failure, yet you can still easily determine the
  1504.                actual value returned by the operating system:
  1505.  
  1506.                    ($retval = ioctl(...)) || ($retval = -1);
  1507.                    printf "System returned %d\n", $retval;
  1508.  
  1509.        join EXPR,LIST
  1510.                Joins the separate strings of LIST or ARRAY into a
  1511.                single string with fields separated by the value
  1512.                of EXPR, and returns the string.  Example:
  1513.  
  1514.                    $_ = join(':', $login,$passwd,$uid,$gid,$gcos,$home,$shell);
  1515.  
  1516.                See the split entry in the perlfunc manpage.
  1517.  
  1518.        keys ASSOC_ARRAY
  1519.                Returns a normal array consisting of all the keys
  1520.                of the named associative array.  (In a scalar
  1521.                context, returns the number of keys.)  The keys
  1522.                are returned in an apparently random order, but it
  1523.                is the same order as either the values() or each()
  1524.                function produces (given that the associative
  1525.                array has not been modified).  Here is yet another
  1526.                way to print your environment:
  1527.  
  1528.                    @keys = keys %ENV;
  1529.                    @values = values %ENV;
  1530.                    while ($#keys >= 0) {
  1531.                        print pop(@keys), '=', pop(@values), "\n";
  1532.                    }
  1533.  
  1534.                or how about sorted by key:
  1535.                    foreach $key (sort(keys %ENV)) {
  1536.                        print $key, '=', $ENV{$key}, "\n";
  1537.                    }
  1538.  
  1539.                To sort an array by value, you'll need to use a
  1540.                sort{} function.  Here's a descending numeric sort
  1541.                of a hash by its values:
  1542.  
  1543.                    foreach $key (sort { $hash{$b} <=> $hash{$a} } keys %hash)) {
  1544.                        printf "%4d %s\n", $hash{$key}, $key;
  1545.                    }
  1546.  
  1547.        kill LIST
  1548.                Sends a signal to a list of processes.  The first
  1549.                element of the list must be the signal to send.
  1550.                Returns the number of processes successfully
  1551.                signaled.
  1552.  
  1553.                    $cnt = kill 1, $child1, $child2;
  1554.                    kill 9, @goners;
  1555.  
  1556.                Unlike in the shell, in Perl if the SIGNAL is
  1557.                negative, it kills process groups instead of
  1558.                processes.  (On System V, a negative PROCESS
  1559.                number will also kill process groups, but that's
  1560.                not portable.)  That means you usually want to use
  1561.                positive not negative signals.  You may also use a
  1562.                signal name in quotes.  See the the section on
  1563.                Signals in the perlipc manpage man page for
  1564.                details.
  1565.  
  1566.        last LABEL
  1567.  
  1568.        last    The last command is like the break statement in C
  1569.                (as used in loops); it immediately exits the loop
  1570.                in question.  If the LABEL is omitted, the command
  1571.                refers to the innermost enclosing loop.  The
  1572.                continue block, if any, is not executed:
  1573.  
  1574.                    LINE: while (<STDIN>) {
  1575.                        last LINE if /^$/;      # exit when done with header
  1576.                        ...
  1577.                    }
  1578.  
  1579.        lc EXPR Returns an lowercased version of EXPR.  This is
  1580.                the internal function implementing the \L escape
  1581.                in double-quoted strings.  Should respect any
  1582.                POSIX setlocale() settings.
  1583.  
  1584.        lcfirst EXPR
  1585.                Returns the value of EXPR with the first character
  1586.                lowercased.  This is the internal function
  1587.                implementing the \l escape in double-quoted
  1588.                strings.  Should respect any POSIX setlocale()
  1589.                settings.
  1590.  
  1591.        length EXPR
  1592.                Returns the length in characters of the value of
  1593.                EXPR.  If EXPR is omitted, returns length of $_.
  1594.  
  1595.        link OLDFILE,NEWFILE
  1596.                Creates a new filename linked to the old filename.
  1597.                Returns 1 for success, 0 otherwise.
  1598.  
  1599.        listen SOCKET,QUEUESIZE
  1600.                Does the same thing that the listen system call
  1601.                does.  Returns TRUE if it succeeded, FALSE
  1602.                otherwise.  See example in the section on Sockets:
  1603.                Client/Server Communication in the perlipc
  1604.                manpage.
  1605.  
  1606.        local EXPR
  1607.                A local modifies the listed variables to be local
  1608.                to the enclosing block, subroutine, eval{} or do.
  1609.                If more than one value is listed, the list must be
  1610.                placed in parens.  See L<perlsub/"Temporary Values
  1611.                via local()"> for details.
  1612.  
  1613.                But you really probably want to be using my()
  1614.                instead, because local() isn't what most people
  1615.                think of as "local").  See L<perlsub/"Private
  1616.                Variables via my()"> for details.
  1617.  
  1618.        localtime EXPR
  1619.                Converts a time as returned by the time function
  1620.                to a 9-element array with the time analyzed for
  1621.                the local timezone.  Typically used as follows:
  1622.  
  1623.                    ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
  1624.                                                                localtime(time);
  1625.  
  1626.                All array elements are numeric, and come straight
  1627.                out of a struct tm.  In particular this means that
  1628.                $mon has the range 0..11 and $wday has the range
  1629.                0..6.  If EXPR is omitted, does localtime(time).
  1630.  
  1631.                In a scalar context, prints out the ctime(3)
  1632.                value:
  1633.  
  1634.                    $now_string = localtime;  # e.g. "Thu Oct 13 04:54:34 1994"
  1635.  
  1636.                Also see the timelocal.pl library, and the
  1637.                strftime(3) function available via the POSIX
  1638.                modulie.
  1639.  
  1640.        log EXPR
  1641.                Returns logarithm (base e) of EXPR.  If EXPR is
  1642.                omitted, returns log of $_.
  1643.  
  1644.        lstat FILEHANDLE
  1645.  
  1646.        lstat EXPR
  1647.                Does the same thing as the stat() function, but
  1648.                stats a symbolic link instead of the file the
  1649.                symbolic link points to.  If symbolic links are
  1650.                unimplemented on your system, a normal stat() is
  1651.                done.
  1652.  
  1653.        m//     The match operator.  See the perlop manpage.
  1654.  
  1655.        map BLOCK LIST
  1656.  
  1657.        map EXPR,LIST
  1658.                Evaluates the BLOCK or EXPR for each element of
  1659.                LIST (locally setting $_ to each element) and
  1660.                returns the list value composed of the results of
  1661.                each such evaluation.  Evaluates BLOCK or EXPR in
  1662.                a list context, so each element of LIST may
  1663.                produce zero, one, or more elements in the
  1664.                returned value.
  1665.  
  1666.                    @chars = map(chr, @nums);
  1667.  
  1668.                translates a list of numbers to the corresponding
  1669.                characters.  And
  1670.  
  1671.                    %hash = map { getkey($_) => $_ } @array;
  1672.  
  1673.                is just a funny way to write
  1674.  
  1675.                    %hash = ();
  1676.                    foreach $_ (@array) {
  1677.                        $hash{getkey($_)} = $_;
  1678.                    }
  1679.  
  1680.        mkdir FILENAME,MODE
  1681.                Creates the directory specified by FILENAME, with
  1682.                permissions specified by MODE (as modified by
  1683.                umask).  If it succeeds it returns 1, otherwise it
  1684.                returns 0 and sets $! (errno).
  1685.  
  1686.        msgctl ID,CMD,ARG
  1687.                Calls the System V IPC function msgctl(2).  If CMD
  1688.                is &IPC_STAT, then ARG must be a variable which
  1689.                will hold the returned msqid_ds structure.
  1690.                Returns like ioctl: the undefined value for error,
  1691.                "0 but true" for zero, or the actual return value
  1692.                otherwise.
  1693.        msgget KEY,FLAGS
  1694.                Calls the System V IPC function msgget(2).
  1695.                Returns the message queue id, or the undefined
  1696.                value if there is an error.
  1697.  
  1698.        msgsnd ID,MSG,FLAGS
  1699.                Calls the System V IPC function msgsnd to send the
  1700.                message MSG to the message queue ID.  MSG must
  1701.                begin with the long integer message type, which
  1702.                may be created with pack("l", $type).  Returns
  1703.                TRUE if successful, or FALSE if there is an error.
  1704.  
  1705.        msgrcv ID,VAR,SIZE,TYPE,FLAGS
  1706.                Calls the System V IPC function msgrcv to receive
  1707.                a message from message queue ID into variable VAR
  1708.                with a maximum message size of SIZE.  Note that if
  1709.                a message is received, the message type will be
  1710.                the first thing in VAR, and the maximum length of
  1711.                VAR is SIZE plus the size of the message type.
  1712.                Returns TRUE if successful, or FALSE if there is
  1713.                an error.
  1714.  
  1715.        my EXPR A "my" declares the listed variables to be local
  1716.                (lexically) to the enclosing block, subroutine,
  1717.                eval, or do/require/use'd file.  If more than one
  1718.                value is listed, the list must be placed in
  1719.                parens.  See the section on Private Variables via
  1720.                my() in the perlsub manpage for details.
  1721.  
  1722.        next LABEL
  1723.  
  1724.        next    The next command is like the continue statement in
  1725.                C; it starts the next iteration of the loop:
  1726.  
  1727.                    LINE: while (<STDIN>) {
  1728.                        next LINE if /^#/;      # discard comments
  1729.                        ...
  1730.                    }
  1731.  
  1732.                Note that if there were a continue block on the
  1733.                above, it would get executed even on discarded
  1734.                lines.  If the LABEL is omitted, the command
  1735.                refers to the innermost enclosing loop.
  1736.  
  1737.        no Module LIST
  1738.                See the "use" function, which "no" is the opposite
  1739.                of.
  1740.  
  1741.        oct EXPR
  1742.                Interprets EXPR as an octal string and returns the
  1743.                corresponding decimal value.  (If EXPR happens to
  1744.                start off with 0x, interprets it as a hex string
  1745.                instead.)  The following will handle decimal,
  1746.                octal, and hex in the standard Perl or C notation:
  1747.                    $val = oct($val) if $val =~ /^0/;
  1748.  
  1749.                If EXPR is omitted, uses $_.
  1750.  
  1751.        open FILEHANDLE,EXPR
  1752.  
  1753.        open FILEHANDLE
  1754.                Opens the file whose filename is given by EXPR,
  1755.                and associates it with FILEHANDLE.  If FILEHANDLE
  1756.                is an expression, its value is used as the name of
  1757.                the real filehandle wanted.  If EXPR is omitted,
  1758.                the scalar variable of the same name as the
  1759.                FILEHANDLE contains the filename.  If the filename
  1760.                begins with "<" or nothing, the file is opened for
  1761.                input.  If the filename begins with ">", the file
  1762.                is opened for output.  If the filename begins with
  1763.                ">>", the file is opened for appending.  You can
  1764.                put a '+' in front of the '>' or '<' to indicate
  1765.                that you want both read and write access to the
  1766.                file; thus '+<' is usually preferred for
  1767.                read/write updates--the '+>' mode would clobber
  1768.                the file first.  These correspond to the fopen(3)
  1769.                modes of 'r', 'r+', 'w', 'w+', 'a', and 'a+'.
  1770.  
  1771.                If the filename begins with "|", the filename is
  1772.                interpreted as a command to which output is to be
  1773.                piped, and if the filename ends with a "|", the
  1774.                filename is interpreted See the section on Using
  1775.                open() for IPC in the perlipc manpage for more
  1776.                examples of this.  as command which pipes input to
  1777.                us.  (You may not have a raw open() to a command
  1778.                that pipes both in and out, but see See the open2
  1779.                manpage, the open3 manpage, and the section on
  1780.                Bidirectional Communication in the perlipc manpage
  1781.                for alternatives.)
  1782.  
  1783.                Opening '-' opens STDIN and opening '>-' opens
  1784.                STDOUT.  Open returns non-zero upon success, the
  1785.                undefined value otherwise.  If the open involved a
  1786.                pipe, the return value happens to be the pid of
  1787.                the subprocess.
  1788.  
  1789.                If you're unfortunate enough to be running Perl on
  1790.                a system that distinguishes between text files and
  1791.                binary files (modern operating systems don't
  1792.                care), then you should check out the binmode entry
  1793.                elsewhere in this documentfor tips for dealing
  1794.                with this.  The key distinction between systems
  1795.                that need binmode and those that don't is their
  1796.                text file formats.  Systems like Unix and Plan9
  1797.                that delimit lines with a single character, and
  1798.                that encode that character in C as '\n', do not
  1799.                need binmode.  The rest need it.
  1800.  
  1801.                Examples:
  1802.  
  1803.                    $ARTICLE = 100;
  1804.                    open ARTICLE or die "Can't find article $ARTICLE: $!\n";
  1805.                    while (<ARTICLE>) {...
  1806.  
  1807.                    open(LOG, '>>/usr/spool/news/twitlog'); # (log is reserved)
  1808.  
  1809.                    open(DBASE, '+<dbase.mine');            # open for update
  1810.  
  1811.                    open(ARTICLE, "caesar <$article |");    # decrypt article
  1812.  
  1813.                    open(EXTRACT, "|sort >/tmp/Tmp$$");     # $$ is our process id
  1814.  
  1815.                    # process argument list of files along with any includes
  1816.  
  1817.                    foreach $file (@ARGV) {
  1818.                        process($file, 'fh00');
  1819.                    }
  1820.  
  1821.                    sub process {
  1822.                        local($filename, $input) = @_;
  1823.                        $input++;               # this is a string increment
  1824.                        unless (open($input, $filename)) {
  1825.                            print STDERR "Can't open $filename: $!\n";
  1826.                            return;
  1827.                        }
  1828.  
  1829.                        while (<$input>) {              # note use of indirection
  1830.                            if (/^#include "(.*)"/) {
  1831.                                process($1, $input);
  1832.                                next;
  1833.                            }
  1834.                            ...         # whatever
  1835.                        }
  1836.                    }
  1837.  
  1838.                You may also, in the Bourne shell tradition,
  1839.                specify an EXPR beginning with ">&", in which case
  1840.                the rest of the string is interpreted as the name
  1841.                of a filehandle (or file descriptor, if numeric)
  1842.                which is to be duped and opened.  You may use &
  1843.                after >, >>, <, +>, +>> and +<.  The mode you
  1844.                specify should match the mode of the original
  1845.                filehandle.  (Duping a filehandle does not take
  1846.                into acount any existing contents of stdio
  1847.                buffers.)  Here is a script that saves, redirects,
  1848.                and restores STDOUT and STDERR:
  1849.  
  1850.                    #!/usr/bin/perl
  1851.                    open(SAVEOUT, ">&STDOUT");
  1852.                    open(SAVEERR, ">&STDERR");
  1853.  
  1854.                    open(STDOUT, ">foo.out") || die "Can't redirect stdout";
  1855.                    open(STDERR, ">&STDOUT") || die "Can't dup stdout";
  1856.  
  1857.                    select(STDERR); $| = 1;     # make unbuffered
  1858.                    select(STDOUT); $| = 1;     # make unbuffered
  1859.  
  1860.                    print STDOUT "stdout 1\n";  # this works for
  1861.                    print STDERR "stderr 1\n";  # subprocesses too
  1862.  
  1863.                    close(STDOUT);
  1864.                    close(STDERR);
  1865.  
  1866.                    open(STDOUT, ">&SAVEOUT");
  1867.                    open(STDERR, ">&SAVEERR");
  1868.  
  1869.                    print STDOUT "stdout 2\n";
  1870.                    print STDERR "stderr 2\n";
  1871.  
  1872.                If you specify "<&=N", where N is a number, then
  1873.                Perl will do an equivalent of C's fdopen() of that
  1874.                file descriptor; this is more parsimonious of file
  1875.                descriptors.  For example:
  1876.  
  1877.                    open(FILEHANDLE, "<&=$fd")
  1878.  
  1879.                If you open a pipe on the command "-", i.e. either
  1880.                "|-" or "-|", then there is an implicit fork done,
  1881.                and the return value of open is the pid of the
  1882.                child within the parent process, and 0 within the
  1883.                child process.  (Use defined($pid) to determine
  1884.                whether the open was successful.)  The filehandle
  1885.                behaves normally for the parent, but i/o to that
  1886.                filehandle is piped from/to the STDOUT/STDIN of
  1887.                the child process.  In the child process the
  1888.                filehandle isn't opened--i/o happens from/to the
  1889.                new STDOUT or STDIN.  Typically this is used like
  1890.                the normal piped open when you want to exercise
  1891.                more control over just how the pipe command gets
  1892.                executed, such as when you are running setuid, and
  1893.                don't want to have to scan shell commands for
  1894.                metacharacters.  The following pairs are more or
  1895.                less equivalent:
  1896.  
  1897.                    open(FOO, "|tr '[a-z]' '[A-Z]'");
  1898.                    open(FOO, "|-") || exec 'tr', '[a-z]', '[A-Z]';
  1899.  
  1900.                    open(FOO, "cat -n '$file'|");
  1901.                    open(FOO, "-|") || exec 'cat', '-n', $file;
  1902.  
  1903.                See the section on Safe Pipe Opens in the perlipc
  1904.                manpage for more examples of this.
  1905.  
  1906.                Explicitly closing any piped filehandle causes the
  1907.                parent process to wait for the child to finish,
  1908.                and returns the status value in $?.  Note: on any
  1909.                operation which may do a fork, unflushed buffers
  1910.                remain unflushed in both processes, which means
  1911.                you may need to set $| to avoid duplicate output.
  1912.  
  1913.                Using the FileHandle constructor from the
  1914.                FileHandle package, you can generate anonymous
  1915.                filehandles which have the scope of whatever
  1916.                variables hold references to them, and
  1917.                automatically close whenever and however you leave
  1918.                that scope:
  1919.  
  1920.                    use FileHandle;
  1921.                    ...
  1922.                    sub read_myfile_munged {
  1923.                        my $ALL = shift;
  1924.                        my $handle = new FileHandle;
  1925.                        open($handle, "myfile") or die "myfile: $!";
  1926.                        $first = <$handle>
  1927.                            or return ();     # Automatically closed here.
  1928.                        mung $first or die "mung failed";       # Or here.
  1929.                        return $first, <$handle> if $ALL;       # Or here.
  1930.                        $first;                                 # Or here.
  1931.                    }
  1932.  
  1933.                The filename that is passed to open will have
  1934.                leading and trailing whitespace deleted.  In order
  1935.                to open a file with arbitrary weird characters in
  1936.                it, it's necessary to protect any leading and
  1937.                trailing whitespace thusly:
  1938.  
  1939.                    $file =~ s#^(\s)#./$1#;
  1940.                    open(FOO, "< $file\0");
  1941.  
  1942.                If you want a "real" C open() (see the open(2)
  1943.                manpage on your system), then you should use the
  1944.                sysopen() function.  This is another way to
  1945.                protect your filenames from interpretation.  For
  1946.                example:
  1947.  
  1948.                    use FileHandle;
  1949.                    sysopen(HANDLE, $path, O_RDWR|O_CREAT|O_EXCL, 0700)
  1950.                        or die "sysopen $path: $!";
  1951.                    HANDLE->autoflush(1);
  1952.                    HANDLE->print("stuff $$\n");
  1953.                    seek(HANDLE, 0, 0);
  1954.                    print "File contains: ", <HANDLE>;
  1955.  
  1956.                See the seek() entry elsewhere in this documentfor
  1957.                some details about mixing reading and writing.
  1958.  
  1959.        opendir DIRHANDLE,EXPR
  1960.                Opens a directory named EXPR for processing by
  1961.                readdir(), telldir(), seekdir(), rewinddir() and
  1962.                closedir().  Returns TRUE if successful.
  1963.                DIRHANDLEs have their own namespace separate from
  1964.                FILEHANDLEs.
  1965.  
  1966.        ord EXPR
  1967.                Returns the numeric ascii value of the first
  1968.                character of EXPR.  If EXPR is omitted, uses $_.
  1969.  
  1970.        pack TEMPLATE,LIST
  1971.                Takes an array or list of values and packs it into
  1972.                a binary structure, returning the string
  1973.                containing the structure.  The TEMPLATE is a
  1974.                sequence of characters that give the order and
  1975.                type of values, as follows:
  1976.  
  1977.                    A   An ascii string, will be space padded.
  1978.                    a   An ascii string, will be null padded.
  1979.                    b   A bit string (ascending bit order, like vec()).
  1980.                    B   A bit string (descending bit order).
  1981.                    h   A hex string (low nybble first).
  1982.                    H   A hex string (high nybble first).
  1983.  
  1984.                    c   A signed char value.
  1985.                    C   An unsigned char value.
  1986.                    s   A signed short value.
  1987.                    S   An unsigned short value.
  1988.                    i   A signed integer value.
  1989.                    I   An unsigned integer value.
  1990.                    l   A signed long value.
  1991.                    L   An unsigned long value.
  1992.  
  1993.                    n   A short in "network" order.
  1994.                    N   A long in "network" order.
  1995.                    v   A short in "VAX" (little-endian) order.
  1996.                    V   A long in "VAX" (little-endian) order.
  1997.  
  1998.                    f   A single-precision float in the native format.
  1999.                    d   A double-precision float in the native format.
  2000.  
  2001.                    p   A pointer to a null-terminated string.
  2002.                    P   A pointer to a structure (fixed-length string).
  2003.  
  2004.                    u   A uuencoded string.
  2005.  
  2006.                    x   A null byte.
  2007.                    X   Back up a byte.
  2008.                    @   Null fill to absolute position.
  2009.  
  2010.                Each letter may optionally be followed by a number
  2011.                which gives a repeat count.  With all types except
  2012.                "a", "A", "b", "B", "h" and "H", and "P" the pack
  2013.                function will gobble up that many values from the
  2014.                LIST.  A * for the repeat count means to use
  2015.                however many items are left.  The "a" and "A"
  2016.                types gobble just one value, but pack it as a
  2017.                string of length count, padding with nulls or
  2018.                spaces as necessary.  (When unpacking, "A" strips
  2019.                trailing spaces and nulls, but "a" does not.)
  2020.                Likewise, the "b" and "B" fields pack a string
  2021.                that many bits long.  The "h" and "H" fields pack
  2022.                a string that many nybbles long.  The "P" packs a
  2023.                pointer to a structure of the size indicated by
  2024.                the length.  Real numbers (floats and doubles) are
  2025.                in the native machine format only; due to the
  2026.                multiplicity of floating formats around, and the
  2027.                lack of a standard "network" representation, no
  2028.                facility for interchange has been made.  This
  2029.                means that packed floating point data written on
  2030.                one machine may not be readable on another - even
  2031.                if both use IEEE floating point arithmetic (as the
  2032.                endian-ness of the memory representation is not
  2033.                part of the IEEE spec).  Note that Perl uses
  2034.                doubles internally for all numeric calculation,
  2035.                and converting from double into float and thence
  2036.                back to double again will lose precision (i.e.
  2037.                unpack("f", pack("f", $foo)) will not in general
  2038.                equal $foo).
  2039.  
  2040.                Examples:
  2041.  
  2042.                    $foo = pack("cccc",65,66,67,68);
  2043.                    # foo eq "ABCD"
  2044.                    $foo = pack("c4",65,66,67,68);
  2045.                    # same thing
  2046.  
  2047.                    $foo = pack("ccxxcc",65,66,67,68);
  2048.                    # foo eq "AB\0\0CD"
  2049.  
  2050.                    $foo = pack("s2",1,2);
  2051.                    # "\1\0\2\0" on little-endian
  2052.                    # "\0\1\0\2" on big-endian
  2053.  
  2054.                    $foo = pack("a4","abcd","x","y","z");
  2055.                    # "abcd"
  2056.  
  2057.                    $foo = pack("aaaa","abcd","x","y","z");
  2058.                    # "axyz"
  2059.  
  2060.                    $foo = pack("a14","abcdefg");
  2061.                    # "abcdefg\0\0\0\0\0\0\0"
  2062.  
  2063.                    $foo = pack("i9pl", gmtime);
  2064.                    # a real struct tm (on my system anyway)
  2065.  
  2066.                    sub bintodec {
  2067.                        unpack("N", pack("B32", substr("0" x 32 . shift, -32)));
  2068.                    }
  2069.  
  2070.                The same template may generally also be used in
  2071.                the unpack function.
  2072.  
  2073.        package NAMESPACE
  2074.                Declares the compilation unit as being in the
  2075.                given namespace.  The scope of the package
  2076.                declaration is from the declaration itself through
  2077.                the end of the enclosing block (the same scope as
  2078.                the local() operator).  All further unqualified
  2079.                dynamic identifiers will be in this namespace.  A
  2080.                package statement only affects dynamic
  2081.                variables--including those you've used local()
  2082.                on--but not lexical variables created with my().
  2083.                Typically it would be the first declaration in a
  2084.                file to be included by the require or use
  2085.                operator.  You can switch into a package in more
  2086.                than one place; it merely influences which symbol
  2087.                table is used by the compiler for the rest of that
  2088.                block.  You can refer to variables and filehandles
  2089.                in other packages by prefixing the identifier with
  2090.                the package name and a double colon:
  2091.                $Package::Variable.  If the package name is null,
  2092.                the main package as assumed.  That is, $::sail is
  2093.                equivalent to $main::sail.
  2094.  
  2095.                See the section on Packages in the perlmod manpage
  2096.                for more information about packages, modules, and
  2097.                classes.  See the perlsub manpage for other
  2098.                scoping issues.
  2099.  
  2100.        pipe READHANDLE,WRITEHANDLE
  2101.                Opens a pair of connected pipes like the
  2102.                corresponding system call.  Note that if you set
  2103.                up a loop of piped processes, deadlock can occur
  2104.                unless you are very careful.  In addition, note
  2105.                that Perl's pipes use stdio buffering, so you may
  2106.                need to set $| to flush your WRITEHANDLE after
  2107.                each command, depending on the application.
  2108.  
  2109.                See the open2 manpage, the open3 manpage, and the
  2110.                section on Bidirectional Communication in the
  2111.                perlipc manpage for examples of such things.
  2112.  
  2113.        pop ARRAY
  2114.                Pops and returns the last value of the array,
  2115.                shortening the array by 1.  Has a similar effect
  2116.                to
  2117.  
  2118.                    $tmp = $ARRAY[$#ARRAY--];
  2119.  
  2120.                If there are no elements in the array, returns the
  2121.                undefined value.  If ARRAY is omitted, pops the
  2122.                @ARGV array in the main program, and the @_ array
  2123.                in subroutines, just like shift().
  2124.        pos SCALAR
  2125.                Returns the offset of where the last m//g search
  2126.                left off for the variable in question.  May be
  2127.                modified to change that offset.
  2128.  
  2129.        print FILEHANDLE LIST
  2130.  
  2131.        print LIST
  2132.  
  2133.        print   Prints a string or a comma-separated list of
  2134.                strings.  Returns TRUE if successful.  FILEHANDLE
  2135.                may be a scalar variable name, in which case the
  2136.                variable contains the name of or a reference to
  2137.                the filehandle, thus introducing one level of
  2138.                indirection.  (NOTE: If FILEHANDLE is a variable
  2139.                and the next token is a term, it may be
  2140.                misinterpreted as an operator unless you interpose
  2141.                a + or put parens around the arguments.)  If
  2142.                FILEHANDLE is omitted, prints by default to
  2143.                standard output (or to the last selected output
  2144.                channel--see select()).  If LIST is also omitted,
  2145.                prints $_ to STDOUT.  To set the default output
  2146.                channel to something other than STDOUT use the
  2147.                select operation.  Note that, because print takes
  2148.                a LIST, anything in the LIST is evaluated in a
  2149.                list context, and any subroutine that you call
  2150.                will have one or more of its expressions evaluated
  2151.                in a list context.  Also be careful not to follow
  2152.                the print keyword with a left parenthesis unless
  2153.                you want the corresponding right parenthesis to
  2154.                terminate the arguments to the print--interpose a
  2155.                + or put parens around all the arguments.
  2156.  
  2157.                Note that if you're storing FILEHANDLES in an
  2158.                array or other expression, you will have to use a
  2159.                block returning its value instead
  2160.  
  2161.                    print { $files[$i] } "stuff\n";
  2162.                    print { $OK ? STDOUT : STDERR } "stuff\n";
  2163.  
  2164.        printf FILEHANDLE LIST
  2165.  
  2166.        printf LIST
  2167.                Equivalent to a "print FILEHANDLE sprintf(LIST)".
  2168.                The first argument of the list will be interpreted
  2169.                as the printf format.
  2170.  
  2171.        push ARRAY,LIST
  2172.                Treats ARRAY as a stack, and pushes the values of
  2173.                LIST onto the end of ARRAY.  The length of ARRAY
  2174.                increases by the length of LIST.  Has the same
  2175.                effect as
  2176.  
  2177.                    for $value (LIST) {
  2178.                        $ARRAY[++$#ARRAY] = $value;
  2179.                    }
  2180.  
  2181.                but is more efficient.  Returns the new number of
  2182.                elements in the array.
  2183.  
  2184.        q/STRING/
  2185.  
  2186.        qq/STRING/
  2187.  
  2188.        qx/STRING/
  2189.  
  2190.        qw/STRING/
  2191.                Generalized quotes.  See the perlop manpage.
  2192.  
  2193.        quotemeta EXPR
  2194.                Returns the value of EXPR with with all regular
  2195.                expression metacharacters backslashed.  This is
  2196.                the internal function implementing the \Q escape
  2197.                in double-quoted strings.
  2198.  
  2199.        rand EXPR
  2200.  
  2201.        rand    Returns a random fractional number between 0 and
  2202.                the value of EXPR.  (EXPR should be positive.)  If
  2203.                EXPR is omitted, returns a value between 0 and 1.
  2204.                This function produces repeatable sequences unless
  2205.                srand() is invoked.  See also srand().
  2206.  
  2207.                (Note: if your rand function consistently returns
  2208.                numbers that are too large or too small, then your
  2209.                version of Perl was probably compiled with the
  2210.                wrong number of RANDBITS.  As a workaround, you
  2211.                can usually multiply EXPR by the correct power of
  2212.                2 to get the range you want.  This will make your
  2213.                script unportable, however.  It's better to
  2214.                recompile if you can.)
  2215.  
  2216.        read FILEHANDLE,SCALAR,LENGTH,OFFSET
  2217.  
  2218.        read FILEHANDLE,SCALAR,LENGTH
  2219.                Attempts to read LENGTH bytes of data into
  2220.                variable SCALAR from the specified FILEHANDLE.
  2221.                Returns the number of bytes actually read, or
  2222.                undef if there was an error.  SCALAR will be grown
  2223.                or shrunk to the length actually read.  An OFFSET
  2224.                may be specified to place the read data at some
  2225.                other place than the beginning of the string.
  2226.                This call is actually implemented in terms of
  2227.                stdio's fread call.  To get a true read system
  2228.                call, see sysread().
  2229.  
  2230.        readdir DIRHANDLE
  2231.                Returns the next directory entry for a directory
  2232.                opened by opendir().  If used in a list context,
  2233.                returns all the rest of the entries in the
  2234.                directory.  If there are no more entries, returns
  2235.                an undefined value in a scalar context or a null
  2236.                list in a list context.
  2237.  
  2238.                If you're planning to filetest the return values
  2239.                out of a readdir(), you'd better prepend the
  2240.                directory in question.  Otherwise, since we didn't
  2241.                chdir() there, it would have been testing the
  2242.                wrong file.
  2243.  
  2244.                    opendir(DIR, $some_dir) || die "can't opendir $some_dir: $!";
  2245.                    @dots = grep { /^\./ && -f "$some_dir/$_" } readdir(DIR);
  2246.                    closedir DIR;
  2247.  
  2248.        readlink EXPR
  2249.                Returns the value of a symbolic link, if symbolic
  2250.                links are implemented.  If not, gives a fatal
  2251.                error.  If there is some system error, returns the
  2252.                undefined value and sets $! (errno).  If EXPR is
  2253.                omitted, uses $_.
  2254.  
  2255.        recv SOCKET,SCALAR,LEN,FLAGS
  2256.                Receives a message on a socket.  Attempts to
  2257.                receive LENGTH bytes of data into variable SCALAR
  2258.                from the specified SOCKET filehandle.  Actually
  2259.                does a C recvfrom(), so that it can returns the
  2260.                address of the sender.  Returns the undefined
  2261.                value if there's an error.  SCALAR will be grown
  2262.                or shrunk to the length actually read.  Takes the
  2263.                same flags as the system call of the same name.
  2264.                See the section on UDP: Message Passing in the
  2265.                perlipc manpage for examples.
  2266.  
  2267.        redo LABEL
  2268.  
  2269.        redo    The redo command restarts the loop block without
  2270.                evaluating the conditional again.  The continue
  2271.                block, if any, is not executed.  If the LABEL is
  2272.                omitted, the command refers to the innermost
  2273.                enclosing loop.  This command is normally used by
  2274.                programs that want to lie to themselves about what
  2275.                was just input:
  2276.  
  2277.                    # a simpleminded Pascal comment stripper
  2278.                    # (warning: assumes no { or } in strings)
  2279.                    LINE: while (<STDIN>) {
  2280.                        while (s|({.*}.*){.*}|$1 |) {}
  2281.                        s|{.*}| |;
  2282.                        if (s|{.*| |) {
  2283.                            $front = $_;
  2284.                            while (<STDIN>) {
  2285.                                if (/}/) {      # end of comment?
  2286.                                    s|^|$front{|;
  2287.                                    redo LINE;
  2288.                                }
  2289.                            }
  2290.                        }
  2291.                        print;
  2292.                    }
  2293.  
  2294.        ref EXPR
  2295.                Returns a TRUE value if EXPR is a reference, FALSE
  2296.                otherwise.  The value returned depends on the type
  2297.                of thing the reference is a reference to.  Builtin
  2298.                types include:
  2299.  
  2300.                    REF
  2301.                    SCALAR
  2302.                    ARRAY
  2303.                    HASH
  2304.                    CODE
  2305.                    GLOB
  2306.  
  2307.                If the referenced object has been blessed into a
  2308.                package, then that package name is returned
  2309.                instead.  You can think of ref() as a typeof()
  2310.                operator.
  2311.  
  2312.                    if (ref($r) eq "HASH") {
  2313.                        print "r is a reference to an associative array.\n";
  2314.                    }
  2315.                    if (!ref ($r) {
  2316.                        print "r is not a reference at all.\n";
  2317.                    }
  2318.  
  2319.                See also the perlref manpage.
  2320.  
  2321.        rename OLDNAME,NEWNAME
  2322.                Changes the name of a file.  Returns 1 for
  2323.                success, 0 otherwise.  Will not work across
  2324.                filesystem boundaries.
  2325.  
  2326.        require EXPR
  2327.  
  2328.        require Demands some semantics specified by EXPR, or by $_
  2329.                if EXPR is not supplied.  If EXPR is numeric,
  2330.                demands that the current version of Perl ($] or
  2331.                $PERL_VERSION) be equal or greater than EXPR.
  2332.  
  2333.                Otherwise, demands that a library file be included
  2334.                if it hasn't already been included.  The file is
  2335.                included via the do-FILE mechanism, which is
  2336.                essentially just a variety of eval().  Has
  2337.                semantics similar to the following subroutine:
  2338.  
  2339.                    sub require {
  2340.                        local($filename) = @_;
  2341.                        return 1 if $INC{$filename};
  2342.                        local($realfilename,$result);
  2343.                        ITER: {
  2344.                            foreach $prefix (@INC) {
  2345.                                $realfilename = "$prefix/$filename";
  2346.                                if (-f $realfilename) {
  2347.                                    $result = do $realfilename;
  2348.                                    last ITER;
  2349.                                }
  2350.                            }
  2351.                            die "Can't find $filename in \@INC";
  2352.                        }
  2353.                        die $@ if $@;
  2354.                        die "$filename did not return true value" unless $result;
  2355.                        $INC{$filename} = $realfilename;
  2356.                        $result;
  2357.                    }
  2358.  
  2359.                Note that the file will not be included twice
  2360.                under the same specified name.  The file must
  2361.                return TRUE as the last statement to indicate
  2362.                successful execution of any initialization code,
  2363.                so it's customary to end such a file with "1;"
  2364.                unless you're sure it'll return TRUE otherwise.
  2365.                But it's better just to put the "1;", in case you
  2366.                add more statements.
  2367.  
  2368.                If EXPR is a bare word, the require assumes a
  2369.                ".pm" extension for you, to make it easy to load
  2370.                standard modules.  This form of loading of modules
  2371.                does not risk altering your namespace.
  2372.  
  2373.                For a yet-more-powerful import facility, see the
  2374.                the use() entry elsewhere in this documentthe
  2375.                perlmod manpage.
  2376.  
  2377.        reset EXPR
  2378.  
  2379.        reset   Generally used in a continue block at the end of a
  2380.                loop to clear variables and reset ?? searches so
  2381.                that they work again.  The expression is
  2382.                interpreted as a list of single characters
  2383.                (hyphens allowed for ranges).  All variables and
  2384.                arrays beginning with one of those letters are
  2385.                reset to their pristine state.  If the expression
  2386.                is omitted, one-match searches (?pattern?) are
  2387.                reset to match again.  Only resets variables or
  2388.                searches in the current package.  Always returns
  2389.                1.  Examples:
  2390.  
  2391.                    reset 'X';          # reset all X variables
  2392.                    reset 'a-z';        # reset lower case variables
  2393.                    reset;              # just reset ?? searches
  2394.  
  2395.                Resetting "A-Z" is not recommended since you'll
  2396.                wipe out your ARGV and ENV arrays.  Only resets
  2397.                package variables--lexical variables are
  2398.                unaffected, but they clean themselves up on scope
  2399.                exit anyway, so anymore you probably want to use
  2400.                them instead.  See the my entry elsewhere in this
  2401.                document.
  2402.  
  2403.        return LIST
  2404.                Returns from a subroutine or eval with the value
  2405.                specified.  (Note that in the absence of a return
  2406.                a subroutine or eval() will automatically return
  2407.                the value of the last expression evaluated.)
  2408.  
  2409.        reverse LIST
  2410.                In a list context, returns a list value consisting
  2411.                of the elements of LIST in the opposite order.  In
  2412.                a scalar context, returns a string value
  2413.                consisting of the bytes of the first element of
  2414.                LIST in the opposite order.
  2415.  
  2416.                    print reverse <>;                   # line tac
  2417.  
  2418.                    undef $/;
  2419.                    print scalar reverse scalar <>;     # byte tac
  2420.  
  2421.        rewinddir DIRHANDLE
  2422.                Sets the current position to the beginning of the
  2423.                directory for the readdir() routine on DIRHANDLE.
  2424.  
  2425.        rindex STR,SUBSTR,POSITION
  2426.  
  2427.        rindex STR,SUBSTR
  2428.                Works just like index except that it returns the
  2429.                position of the LAST occurrence of SUBSTR in STR.
  2430.                If POSITION is specified, returns the last
  2431.                occurrence at or before that position.
  2432.  
  2433.        rmdir FILENAME
  2434.                Deletes the directory specified by FILENAME if it
  2435.                is empty.  If it succeeds it returns 1, otherwise
  2436.                it returns 0 and sets $! (errno).  If FILENAME is
  2437.                omitted, uses $_.
  2438.  
  2439.        s///    The substitution operator.  See the perlop
  2440.                manpage.
  2441.  
  2442.        scalar EXPR
  2443.                Forces EXPR to be interpreted in a scalar context
  2444.                and returns the value of EXPR.
  2445.  
  2446.                    @counts = ( scalar @a, scalar @b, scalar @c );
  2447.  
  2448.                There is no equivalent operator to force an
  2449.                expression to be interpolated in a list context
  2450.                because it's in practice never needed.  If you
  2451.                really wanted to do so, however, you could use the
  2452.                construction @{[ (some expression) ]}, but usually
  2453.                a simple (some expression) suffices.
  2454.  
  2455.        seek FILEHANDLE,POSITION,WHENCE
  2456.                Randomly positions the file pointer for
  2457.                FILEHANDLE, just like the fseek() call of stdio.
  2458.                FILEHANDLE may be an expression whose value gives
  2459.                the name of the filehandle.  The values for WHENCE
  2460.                are 0 to set the file pointer to POSITION, 1 to
  2461.                set the it to current plus POSITION, and 2 to set
  2462.                it to EOF plus offset.  You may use the values
  2463.                SEEK_SET, SEEK_CUR, and SEEK_END for this from
  2464.                POSIX module.  Returns 1 upon success, 0
  2465.                otherwise.
  2466.  
  2467.                On some systems you have to do a seek whenever you
  2468.                switch between reading and writing.  Amongst other
  2469.                things, this may have the effect of calling
  2470.                stdio's clearerr(3).  A "whence" of 1 (SEEK_CUR)
  2471.                is useful for not moving the file pointer:
  2472.  
  2473.                    seek(TEST,0,1);
  2474.  
  2475.                This is also useful for applications emulating
  2476.                tail -f.  Once you hit EOF on your read, and then
  2477.                sleep for a while, you might have to stick in a
  2478.                seek() to reset things.  First the simple trick
  2479.                listed above to clear the filepointer.  The seek()
  2480.                doesn't change the current position, but it does
  2481.                clear the end-of-file condition on the handle, so
  2482.                that the next <FILE> makes Perl try again to read
  2483.                something.  Hopefully.
  2484.  
  2485.                If that doesn't work (some stdios are particularly
  2486.                cantankerous), then you may need something more
  2487.                like this:
  2488.  
  2489.                    for (;;) {
  2490.                        for ($curpos = tell(FILE); $_ = <FILE>; $curpos = tell(FILE)) {
  2491.                            # search for some stuff and put it into files
  2492.                        }
  2493.                        sleep($for_a_while);
  2494.                        seek(FILE, $curpos, 0);
  2495.                    }
  2496.  
  2497.        seekdir DIRHANDLE,POS
  2498.                Sets the current position for the readdir()
  2499.                routine on DIRHANDLE.  POS must be a value
  2500.                returned by telldir().  Has the same caveats about
  2501.                possible directory compaction as the corresponding
  2502.                system library routine.
  2503.  
  2504.        select FILEHANDLE
  2505.  
  2506.        select  Returns the currently selected filehandle.  Sets
  2507.                the current default filehandle for output, if
  2508.                FILEHANDLE is supplied.  This has two effects:
  2509.                first, a write or a print without a filehandle
  2510.                will default to this FILEHANDLE.  Second,
  2511.                references to variables related to output will
  2512.                refer to this output channel.  For example, if you
  2513.                have to set the top of form format for more than
  2514.                one output channel, you might do the following:
  2515.  
  2516.                    select(REPORT1);
  2517.                    $^ = 'report1_top';
  2518.                    select(REPORT2);
  2519.                    $^ = 'report2_top';
  2520.  
  2521.                FILEHANDLE may be an expression whose value gives
  2522.                the name of the actual filehandle.  Thus:
  2523.  
  2524.                    $oldfh = select(STDERR); $| = 1; select($oldfh);
  2525.  
  2526.                Some programmers may prefer to think of
  2527.                filehandles as objects with methods, preferring to
  2528.                write the last example as:
  2529.  
  2530.                    use FileHandle;
  2531.                    STDERR->autoflush(1);
  2532.  
  2533.        select RBITS,WBITS,EBITS,TIMEOUT
  2534.                This calls the select(2) system call with the
  2535.                bitmasks specified, which can be constructed using
  2536.                fileno() and vec(), along these lines:
  2537.  
  2538.                    $rin = $win = $ein = '';
  2539.                    vec($rin,fileno(STDIN),1) = 1;
  2540.                    vec($win,fileno(STDOUT),1) = 1;
  2541.                    $ein = $rin | $win;
  2542.  
  2543.                If you want to select on many filehandles you
  2544.                might wish to write a subroutine:
  2545.  
  2546.                    sub fhbits {
  2547.                        local(@fhlist) = split(' ',$_[0]);
  2548.                        local($bits);
  2549.                        for (@fhlist) {
  2550.                            vec($bits,fileno($_),1) = 1;
  2551.                        }
  2552.                        $bits;
  2553.                    }
  2554.                    $rin = fhbits('STDIN TTY SOCK');
  2555.  
  2556.                The usual idiom is:
  2557.  
  2558.                    ($nfound,$timeleft) =
  2559.                      select($rout=$rin, $wout=$win, $eout=$ein, $timeout);
  2560.  
  2561.                or to block until something becomes ready just do
  2562.                this
  2563.  
  2564.                    $nfound = select($rout=$rin, $wout=$win, $eout=$ein, undef);
  2565.  
  2566.                Most systems do not both to return anything useful
  2567.                in $timeleft, so calling select() in a scalar
  2568.                context just returns $nfound.
  2569.  
  2570.                Any of the bitmasks can also be undef.  The
  2571.                timeout, if specified, is in seconds, which may be
  2572.                fractional.  Note: not all implementations are
  2573.                capable of returning the $timeleft.  If not, they
  2574.                always return $timeleft equal to the supplied
  2575.                $timeout.
  2576.  
  2577.                You can effect a 250-microsecond sleep this way:
  2578.  
  2579.                    select(undef, undef, undef, 0.25);
  2580.  
  2581.                WARNING: Do not attempt to mix buffered I/O (like
  2582.                read() or <FH>) with select().  You have to use
  2583.                sysread() instead.
  2584.  
  2585.        semctl ID,SEMNUM,CMD,ARG
  2586.                Calls the System V IPC function semctl.  If CMD is
  2587.                &IPC_STAT or &GETALL, then ARG must be a variable
  2588.                which will hold the returned semid_ds structure or
  2589.                semaphore value array.  Returns like ioctl: the
  2590.                undefined value for error, "0 but true" for zero,
  2591.                or the actual return value otherwise.
  2592.        semget KEY,NSEMS,FLAGS
  2593.                Calls the System V IPC function semget.  Returns
  2594.                the semaphore id, or the undefined value if there
  2595.                is an error.
  2596.  
  2597.        semop KEY,OPSTRING
  2598.                Calls the System V IPC function semop to perform
  2599.                semaphore operations such as signaling and
  2600.                waiting.  OPSTRING must be a packed array of semop
  2601.                structures.  Each semop structure can be generated
  2602.                with pack("sss", $semnum, $semop, $semflag).  The
  2603.                number of semaphore operations is implied by the
  2604.                length of OPSTRING.  Returns TRUE if successful,
  2605.                or FALSE if there is an error.  As an example, the
  2606.                following code waits on semaphore $semnum of
  2607.                semaphore id $semid:
  2608.  
  2609.                    $semop = pack("sss", $semnum, -1, 0);
  2610.                    die "Semaphore trouble: $!\n" unless semop($semid, $semop);
  2611.  
  2612.                To signal the semaphore, replace "-1" with "1".
  2613.  
  2614.        send SOCKET,MSG,FLAGS,TO
  2615.  
  2616.        send SOCKET,MSG,FLAGS
  2617.                Sends a message on a socket.  Takes the same flags
  2618.                as the system call of the same name.  On
  2619.                unconnected sockets you must specify a destination
  2620.                to send TO, in which case it does a C sendto().
  2621.                Returns the number of characters sent, or the
  2622.                undefined value if there is an error.  See the
  2623.                section on UDP: Message Passing in the perlipc
  2624.                manpage for examples.
  2625.  
  2626.        setpgrp PID,PGRP
  2627.                Sets the current process group for the specified
  2628.                PID, 0 for the current process.  Will produce a
  2629.                fatal error if used on a machine that doesn't
  2630.                implement setpgrp(2).
  2631.  
  2632.        setpriority WHICH,WHO,PRIORITY
  2633.                Sets the current priority for a process, a process
  2634.                group, or a user.  (See setpriority(2).)  Will
  2635.                produce a fatal error if used on a machine that
  2636.                doesn't implement setpriority(2).
  2637.  
  2638.        setsockopt SOCKET,LEVEL,OPTNAME,OPTVAL
  2639.                Sets the socket option requested.  Returns
  2640.                undefined if there is an error.  OPTVAL may be
  2641.                specified as undef if you don't want to pass an
  2642.                argument.
  2643.  
  2644.        shift ARRAY
  2645.  
  2646.        shift   Shifts the first value of the array off and
  2647.                returns it, shortening the array by 1 and moving
  2648.                everything down.  If there are no elements in the
  2649.                array, returns the undefined value.  If ARRAY is
  2650.                omitted, shifts the @ARGV array in the main
  2651.                program, and the @_ array in subroutines.  (This
  2652.                is determined lexically.)  See also unshift(),
  2653.                push(), and pop().  Shift() and unshift() do the
  2654.                same thing to the left end of an array that push()
  2655.                and pop() do to the right end.
  2656.  
  2657.        shmctl ID,CMD,ARG
  2658.                Calls the System V IPC function shmctl.  If CMD is
  2659.                &IPC_STAT, then ARG must be a variable which will
  2660.                hold the returned shmid_ds structure.  Returns
  2661.                like ioctl: the undefined value for error, "0 but
  2662.                true" for zero, or the actual return value
  2663.                otherwise.
  2664.  
  2665.        shmget KEY,SIZE,FLAGS
  2666.                Calls the System V IPC function shmget.  Returns
  2667.                the shared memory segment id, or the undefined
  2668.                value if there is an error.
  2669.  
  2670.        shmread ID,VAR,POS,SIZE
  2671.  
  2672.        shmwrite ID,STRING,POS,SIZE
  2673.                Reads or writes the System V shared memory segment
  2674.                ID starting at position POS for size SIZE by
  2675.                attaching to it, copying in/out, and detaching
  2676.                from it.  When reading, VAR must be a variable
  2677.                which will hold the data read.  When writing, if
  2678.                STRING is too long, only SIZE bytes are used; if
  2679.                STRING is too short, nulls are written to fill out
  2680.                SIZE bytes.  Return TRUE if successful, or FALSE
  2681.                if there is an error.
  2682.  
  2683.        shutdown SOCKET,HOW
  2684.                Shuts down a socket connection in the manner
  2685.                indicated by HOW, which has the same
  2686.                interpretation as in the system call of the same
  2687.                name.
  2688.  
  2689.        sin EXPR
  2690.                Returns the sine of EXPR (expressed in radians).
  2691.                If EXPR is omitted, returns sine of $_.
  2692.  
  2693.        sleep EXPR
  2694.  
  2695.        sleep   Causes the script to sleep for EXPR seconds, or
  2696.                forever if no EXPR.  May be interrupted by sending
  2697.                the process a SIGALRM.  Returns the number of
  2698.                seconds actually slept.  You probably cannot mix
  2699.                alarm() and sleep() calls, since sleep() is often
  2700.                implemented using alarm().
  2701.  
  2702.                On some older systems, it may sleep up to a full
  2703.                second less than what you requested, depending on
  2704.                how it counts seconds.  Most modern systems always
  2705.                sleep the full amount.
  2706.  
  2707.                For delays of finer granularity than one second,
  2708.                you may use Perl's syscall() interface to access
  2709.                setitimer(2) if your system supports it, or else
  2710.                see the select() entry elsewhere in this
  2711.                documentbelow.
  2712.  
  2713.        socket SOCKET,DOMAIN,TYPE,PROTOCOL
  2714.                Opens a socket of the specified kind and attaches
  2715.                it to filehandle SOCKET.  DOMAIN, TYPE and
  2716.                PROTOCOL are specified the same as for the system
  2717.                call of the same name.  You should "use Socket;"
  2718.                first to get the proper definitions imported.  See
  2719.                the example in the section on Sockets:
  2720.                Client/Server Communication in the perlipc
  2721.                manpage.
  2722.  
  2723.        socketpair SOCKET1,SOCKET2,DOMAIN,TYPE,PROTOCOL
  2724.                Creates an unnamed pair of sockets in the
  2725.                specified domain, of the specified type.  DOMAIN,
  2726.                TYPE and PROTOCOL are specified the same as for
  2727.                the system call of the same name.  If
  2728.                unimplemented, yields a fatal error.  Returns TRUE
  2729.                if successful.
  2730.  
  2731.        sort SUBNAME LIST
  2732.  
  2733.        sort BLOCK LIST
  2734.  
  2735.        sort LIST
  2736.                Sorts the LIST and returns the sorted list value.
  2737.                Nonexistent values of arrays are stripped out.  If
  2738.                SUBNAME or BLOCK is omitted, sorts in standard
  2739.                string comparison order.  If SUBNAME is specified,
  2740.                it gives the name of a subroutine that returns an
  2741.                integer less than, equal to, or greater than 0,
  2742.                depending on how the elements of the array are to
  2743.                be ordered.  (The <=> and cmp operators are
  2744.                extremely useful in such routines.)  SUBNAME may
  2745.                be a scalar variable name, in which case the value
  2746.                provides the name of the subroutine to use.  In
  2747.                place of a SUBNAME, you can provide a BLOCK as an
  2748.                anonymous, in-line sort subroutine.
  2749.  
  2750.                In the interests of efficiency the normal calling
  2751.                code for subroutines is bypassed, with the
  2752.                following effects: the subroutine may not be a
  2753.                recursive subroutine, and the two elements to be
  2754.                compared are passed into the subroutine not via @_
  2755.                but as the package global variables $a and $b (see
  2756.                example below).  They are passed by reference, so
  2757.                don't modify $a and $b.  And don't try to declare
  2758.                them as lexicals either.
  2759.  
  2760.                Examples:
  2761.  
  2762.                    # sort lexically
  2763.                    @articles = sort @files;
  2764.  
  2765.                    # same thing, but with explicit sort routine
  2766.                    @articles = sort {$a cmp $b} @files;
  2767.  
  2768.                    # now case-insensitively
  2769.                    @articles = sort { uc($a) cmp uc($b)} @files;
  2770.  
  2771.                    # same thing in reversed order
  2772.                    @articles = sort {$b cmp $a} @files;
  2773.  
  2774.                    # sort numerically ascending
  2775.                    @articles = sort {$a <=> $b} @files;
  2776.  
  2777.                    # sort numerically descending
  2778.                    @articles = sort {$b <=> $a} @files;
  2779.  
  2780.                    # sort using explicit subroutine name
  2781.                    sub byage {
  2782.                        $age{$a} <=> $age{$b};  # presuming integers
  2783.                    }
  2784.                    @sortedclass = sort byage @class;
  2785.  
  2786.                    # this sorts the %age associative arrays by value
  2787.                    # instead of key using an inline function
  2788.                    @eldest = sort { $age{$b} <=> $age{$a} } keys %age;
  2789.  
  2790.                    sub backwards { $b cmp $a; }
  2791.                    @harry = ('dog','cat','x','Cain','Abel');
  2792.                    @george = ('gone','chased','yz','Punished','Axed');
  2793.                    print sort @harry;
  2794.                            # prints AbelCaincatdogx
  2795.                    print sort backwards @harry;
  2796.                            # prints xdogcatCainAbel
  2797.                    print sort @george, 'to', @harry;
  2798.                            # prints AbelAxedCainPunishedcatchaseddoggonetoxyz
  2799.  
  2800.                    # inefficiently sort by descending numeric compare using
  2801.                    # the first integer after the first = sign, or the
  2802.                    # whole record case-insensitively otherwise
  2803.  
  2804.                    @new = sort {
  2805.                        ($b =~ /=(\d+)/)[0] <=> ($a =~ /=(\d+)/)[0]
  2806.                                            ||
  2807.                                    uc($a)  cmp  uc($b)
  2808.                    } @old;
  2809.  
  2810.                    # same thing, but much more efficiently;
  2811.                    # we'll build auxiliary indices instead
  2812.                    # for speed
  2813.                    @nums = @caps = ();
  2814.                    for (@old) {
  2815.                        push @nums, /=(\d+)/;
  2816.                        push @caps, uc($_);
  2817.                    }
  2818.  
  2819.                    @new = @old[ sort {
  2820.                                        $nums[$b] <=> $nums[$a]
  2821.                                                 ||
  2822.                                        $caps[$a] cmp $caps[$b]
  2823.                                       } 0..$#old
  2824.                               ];
  2825.  
  2826.                    # same thing using a Schwartzian Transform (no temps)
  2827.                    @new = map { $_->[0] }
  2828.                        sort { $b->[1] <=> $a->[1]
  2829.                                        ||
  2830.                               $a->[2] cmp $b->[2]
  2831.                        } map { [$_, /=(\d+)/, uc($_)] } @old;
  2832.  
  2833.                If you're and using strict, you MUST NOT declare
  2834.                $a and $b as lexicals.  They are package globals.
  2835.                That means if you're in the main package, it's
  2836.  
  2837.                    @articles = sort {$main::b <=> $main::a} @files;
  2838.  
  2839.                or just
  2840.  
  2841.                    @articles = sort {$::b <=> $::a} @files;
  2842.  
  2843.                but if you're in the FooPack package, it's
  2844.  
  2845.                    @articles = sort {$FooPack::b <=> $FooPack::a} @files;
  2846.  
  2847.        splice ARRAY,OFFSET,LENGTH,LIST
  2848.  
  2849.        splice ARRAY,OFFSET,LENGTH
  2850.  
  2851.        splice ARRAY,OFFSET
  2852.                Removes the elements designated by OFFSET and
  2853.                LENGTH from an array, and replaces them with the
  2854.                elements of LIST, if any.  Returns the elements
  2855.                removed from the array.  The array grows or
  2856.                shrinks as necessary.  If LENGTH is omitted,
  2857.                removes everything from OFFSET onward.  The
  2858.                following equivalencies hold (assuming $[ == 0):
  2859.  
  2860.                    push(@a,$x,$y)      splice(@a,$#a+1,0,$x,$y)
  2861.                    pop(@a)             splice(@a,-1)
  2862.                    shift(@a)           splice(@a,0,1)
  2863.                    unshift(@a,$x,$y)   splice(@a,0,0,$x,$y)
  2864.                    $a[$x] = $y         splice(@a,$x,1,$y);
  2865.  
  2866.                Example, assuming array lengths are passed before
  2867.                arrays:
  2868.  
  2869.                    sub aeq {   # compare two list values
  2870.                        local(@a) = splice(@_,0,shift);
  2871.                        local(@b) = splice(@_,0,shift);
  2872.                        return 0 unless @a == @b;       # same len?
  2873.                        while (@a) {
  2874.                            return 0 if pop(@a) ne pop(@b);
  2875.                        }
  2876.                        return 1;
  2877.                    }
  2878.                    if (&aeq($len,@foo[1..$len],0+@bar,@bar)) { ... }
  2879.  
  2880.        split /PATTERN/,EXPR,LIMIT
  2881.  
  2882.        split /PATTERN/,EXPR
  2883.  
  2884.        split /PATTERN/
  2885.  
  2886.        split   Splits a string into an array of strings, and
  2887.                returns it.
  2888.  
  2889.                If not in a list context, returns the number of
  2890.                fields found and splits into the @_ array.  (In a
  2891.                list context, you can force the split into @_ by
  2892.                using ?? as the pattern delimiters, but it still
  2893.                returns the array value.)  The use of implicit
  2894.                split to @_ is deprecated, however.
  2895.  
  2896.                If EXPR is omitted, splits the $_ string.  If
  2897.                PATTERN is also omitted, splits on whitespace
  2898.                (after skipping any leading whitespace).  Anything
  2899.                matching PATTERN is taken to be a delimiter
  2900.                separating the fields.  (Note that the delimiter
  2901.                may be longer than one character.)  If LIMIT is
  2902.                specified and is not negative, splits into no more
  2903.                than that many fields (though it may split into
  2904.                fewer).  If LIMIT is unspecified, trailing null
  2905.                fields are stripped (which potential users of
  2906.                pop() would do well to remember).  If LIMIT is
  2907.                negative, it is treated as if an arbitrarily large
  2908.                LIMIT had been specified.
  2909.  
  2910.                A pattern matching the null string (not to be
  2911.                confused with a null pattern //, which is just one
  2912.                member of the set of patterns matching a null
  2913.                string) will split the value of EXPR into separate
  2914.                characters at each point it matches that way.  For
  2915.                example:
  2916.  
  2917.                    print join(':', split(/ */, 'hi there'));
  2918.  
  2919.                produces the output 'h:i:t:h:e:r:e'.
  2920.  
  2921.                The LIMIT parameter can be used to partially split
  2922.                a line
  2923.  
  2924.                    ($login, $passwd, $remainder) = split(/:/, $_, 3);
  2925.  
  2926.                When assigning to a list, if LIMIT is omitted,
  2927.                Perl supplies a LIMIT one larger than the number
  2928.                of variables in the list, to avoid unnecessary
  2929.                work.  For the list above LIMIT would have been 4
  2930.                by default.  In time critical applications it
  2931.                behooves you not to split into more fields than
  2932.                you really need.
  2933.  
  2934.                If the PATTERN contains parentheses, additional
  2935.                array elements are created from each matching
  2936.                substring in the delimiter.
  2937.  
  2938.                    split(/([,-])/, "1-10,20");
  2939.  
  2940.                produces the list value
  2941.  
  2942.                    (1, '-', 10, ',', 20)
  2943.  
  2944.                If you had the entire header of a normal Unix
  2945.                email message in $header, you could split it up
  2946.                into fields and their values this way:
  2947.  
  2948.                    $header =~ s/\n\s+/ /g;  # fix continuation lines
  2949.                    %hdrs   =  (UNIX_FROM => split /^(.*?):\s*/m, $header);
  2950.  
  2951.                The pattern /PATTERN/ may be replaced with an
  2952.                expression to specify patterns that vary at
  2953.                runtime.  (To do runtime compilation only once,
  2954.                use /$variable/o.)
  2955.  
  2956.                As a special case, specifying a PATTERN of space
  2957.                (' ') will split on white space just as split with
  2958.                no arguments does.  Thus, split(' ') can be used
  2959.                to emulate awk's default behavior, whereas split(/
  2960.                /) will give you as many null initial fields as
  2961.                there are leading spaces.  A split on /\s+/ is
  2962.                like a split(' ') except that any leading
  2963.                whitespace produces a null first field.  A split
  2964.                with no arguments really does a split(' ', $_)
  2965.                internally.
  2966.  
  2967.                Example:
  2968.  
  2969.                    open(passwd, '/etc/passwd');
  2970.                    while (<passwd>) {
  2971.                        ($login, $passwd, $uid, $gid, $gcos,
  2972.                            $home, $shell) = split(/:/);
  2973.                        ...
  2974.                    }
  2975.  
  2976.                (Note that $shell above will still have a newline
  2977.                on it.  See the chop, chomp,  and join entries
  2978.                elsewhere in this document.)
  2979.  
  2980.        sprintf FORMAT,LIST
  2981.                Returns a string formatted by the usual printf
  2982.                conventions of the C language.  See the sprintf(3)
  2983.                manpage or the printf(3) manpage on your system
  2984.                for details.  (The * character for an indirectly
  2985.                specified length is not supported, but you can get
  2986.                the same effect by interpolating a variable into
  2987.                the pattern.)  Some C libraries' implementations
  2988.                of sprintf() can dump core when fed ludicrous
  2989.                arguments.
  2990.  
  2991.        sqrt EXPR
  2992.                Return the square root of EXPR.  If EXPR is
  2993.                omitted, returns square root of $_.
  2994.  
  2995.        srand EXPR
  2996.                Sets the random number seed for the rand operator.
  2997.                If EXPR is omitted, does srand(time).  Many folks
  2998.                use an explicit srand(time ^ $$) instead.  Of
  2999.                course, you'd need something much more random than
  3000.                that for cryptographic purposes, since it's easy
  3001.                to guess the current time.  Checksumming the
  3002.                compressed output of rapidly changing operating
  3003.                system status programs is the usual method.
  3004.                Examples are posted regularly to the
  3005.                comp.security.unix newsgroup.
  3006.  
  3007.        stat FILEHANDLE
  3008.  
  3009.        stat EXPR
  3010.                Returns a 13-element array giving the status info
  3011.                for a file, either the file opened via FILEHANDLE,
  3012.                or named by EXPR.  Returns a null list if the stat
  3013.                fails.  Typically used as follows:
  3014.  
  3015.                    ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
  3016.                       $atime,$mtime,$ctime,$blksize,$blocks)
  3017.                           = stat($filename);
  3018.                Not all fields are supported on all filesystem
  3019.                types.  Here are the meaning of the fields:
  3020.  
  3021.                  dev       device number of filesystem
  3022.                  ino       inode number
  3023.                  mode      file mode  (type and permissions)
  3024.                  nlink     number of (hard) links to the file
  3025.                  uid       numeric user ID of file's owner
  3026.                  gid       numer group ID of file's owner
  3027.                  rdev      the device identifier (special files only)
  3028.                  size      total size of file, in bytes
  3029.                  atime     last access time since the epoch
  3030.                  mtime     last modify time since the epoch
  3031.                  ctime     inode change time (NOT creation type!) since the epoch
  3032.                  blksize   preferred blocksize for file system I/O
  3033.                  blocks    actual number of blocks allocated
  3034.  
  3035.                (The epoch was at 00:00 January 1, 1970 GMT.)
  3036.  
  3037.                If stat is passed the special filehandle
  3038.                consisting of an underline, no stat is done, but
  3039.                the current contents of the stat structure from
  3040.                the last stat or filetest are returned.  Example:
  3041.  
  3042.                    if (-x $file && (($d) = stat(_)) && $d < 0) {
  3043.                        print "$file is executable NFS file\n";
  3044.                    }
  3045.  
  3046.                (This only works on machines for which the device
  3047.                number is negative under NFS.)
  3048.  
  3049.        study SCALAR
  3050.  
  3051.        study   Takes extra time to study SCALAR ($_ if
  3052.                unspecified) in anticipation of doing many pattern
  3053.                matches on the string before it is next modified.
  3054.                This may or may not save time, depending on the
  3055.                nature and number of patterns you are searching
  3056.                on, and on the distribution of character
  3057.                frequencies in the string to be searched--you
  3058.                probably want to compare runtimes with and without
  3059.                it to see which runs faster.  Those loops which
  3060.                scan for many short constant strings (including
  3061.                the constant parts of more complex patterns) will
  3062.                benefit most.  You may have only one study active
  3063.                at a time--if you study a different scalar the
  3064.                first is "unstudied".  (The way study works is
  3065.                this: a linked list of every character in the
  3066.                string to be searched is made, so we know, for
  3067.                example, where all the 'k' characters are.  From
  3068.                each search string, the rarest character is
  3069.                selected, based on some static frequency tables
  3070.                constructed from some C programs and English text.
  3071.                Only those places that contain this "rarest"
  3072.                character are examined.)
  3073.  
  3074.                For example, here is a loop which inserts index
  3075.                producing entries before any line containing a
  3076.                certain pattern:
  3077.  
  3078.                    while (<>) {
  3079.                        study;
  3080.                        print ".IX foo\n" if /\bfoo\b/;
  3081.                        print ".IX bar\n" if /\bbar\b/;
  3082.                        print ".IX blurfl\n" if /\bblurfl\b/;
  3083.                        ...
  3084.                        print;
  3085.                    }
  3086.  
  3087.                In searching for /\bfoo\b/, only those locations
  3088.                in $_ that contain "f" will be looked at, because
  3089.                "f" is rarer than "o".  In general, this is a big
  3090.                win except in pathological cases.  The only
  3091.                question is whether it saves you more time than it
  3092.                took to build the linked list in the first place.
  3093.  
  3094.                Note that if you have to look for strings that you
  3095.                don't know till runtime, you can build an entire
  3096.                loop as a string and eval that to avoid
  3097.                recompiling all your patterns all the time.
  3098.                Together with undefining $/ to input entire files
  3099.                as one record, this can be very fast, often faster
  3100.                than specialized programs like fgrep(1).  The
  3101.                following scans a list of files (@files) for a
  3102.                list of words (@words), and prints out the names
  3103.                of those files that contain a match:
  3104.  
  3105.                    $search = 'while (<>) { study;';
  3106.                    foreach $word (@words) {
  3107.                        $search .= "++\$seen{\$ARGV} if /\\b$word\\b/;\n";
  3108.                    }
  3109.                    $search .= "}";
  3110.                    @ARGV = @files;
  3111.                    undef $/;
  3112.                    eval $search;               # this screams
  3113.                    $/ = "\n";          # put back to normal input delim
  3114.                    foreach $file (sort keys(%seen)) {
  3115.                        print $file, "\n";
  3116.                    }
  3117.  
  3118.        sub BLOCK
  3119.  
  3120.        sub NAME
  3121.  
  3122.        sub NAME BLOCK
  3123.                This is subroutine definition, not a real function
  3124.                per se.  With just a NAME (and possibly
  3125.                prototypes), it's just a forward declaration.
  3126.                Without a NAME, it's an anonymous function
  3127.                declaration, and does actually return a value: the
  3128.                CODE ref of the closure you just created. See the
  3129.                perlsub manpage and the perlref manpage for
  3130.                details.
  3131.  
  3132.        substr EXPR,OFFSET,LEN
  3133.  
  3134.        substr EXPR,OFFSET
  3135.                Extracts a substring out of EXPR and returns it.
  3136.                First character is at offset 0, or whatever you've
  3137.                set $[ to.  If OFFSET is negative, starts that far
  3138.                from the end of the string.  If LEN is omitted,
  3139.                returns everything to the end of the string.  If
  3140.                LEN is negative, leaves that many characters off
  3141.                the end of the string.
  3142.  
  3143.                You can use the substr() function as an lvalue, in
  3144.                which case EXPR must be an lvalue.  If you assign
  3145.                something shorter than LEN, the string will
  3146.                shrink, and if you assign something longer than
  3147.                LEN, the string will grow to accommodate it.  To
  3148.                keep the string the same length you may need to
  3149.                pad or chop your value using sprintf().
  3150.  
  3151.        symlink OLDFILE,NEWFILE
  3152.                Creates a new filename symbolically linked to the
  3153.                old filename.  Returns 1 for success, 0 otherwise.
  3154.                On systems that don't support symbolic links,
  3155.                produces a fatal error at run time.  To check for
  3156.                that, use eval:
  3157.  
  3158.                    $symlink_exists = (eval 'symlink("","");', $@ eq '');
  3159.  
  3160.        syscall LIST
  3161.                Calls the system call specified as the first
  3162.                element of the list, passing the remaining
  3163.                elements as arguments to the system call.  If
  3164.                unimplemented, produces a fatal error.  The
  3165.                arguments are interpreted as follows: if a given
  3166.                argument is numeric, the argument is passed as an
  3167.                int.  If not, the pointer to the string value is
  3168.                passed.  You are responsible to make sure a string
  3169.                is pre-extended long enough to receive any result
  3170.                that might be written into a string.  If your
  3171.                integer arguments are not literals and have never
  3172.                been interpreted in a numeric context, you may
  3173.                need to add 0 to them to force them to look like
  3174.                numbers.
  3175.  
  3176.                    require 'syscall.ph';               # may need to run h2ph
  3177.                    syscall(&SYS_write, fileno(STDOUT), "hi there\n", 9);
  3178.                Note that Perl only supports passing of up to 14
  3179.                arguments to your system call, which in practice
  3180.                should usually suffice.
  3181.  
  3182.        sysopen FILEHANDLE,FILENAME,MODE
  3183.  
  3184.        sysopen FILEHANDLE,FILENAME,MODE,PERMS
  3185.                Opens the file whose filename is given by
  3186.                FILENAME, and associates it with FILEHANDLE.  If
  3187.                FILEHANDLE is an expression, its value is used as
  3188.                the name of the real filehandle wanted.  This
  3189.                function calls the underlying operating system's
  3190.                open function with the parameters FILENAME, MODE,
  3191.                PERMS.
  3192.  
  3193.                The possible values and flag bits of the MODE
  3194.                parameter are system-dependent; they are available
  3195.                via the standard module Fcntl.  However, for
  3196.                historical reasons, some values are universal:
  3197.                zero means read-only, one means write-only, and
  3198.                two means read/write.
  3199.  
  3200.                If the file named by FILENAME does not exist and
  3201.                the open call creates it (typically because MODE
  3202.                includes the O_CREAT flag), then the value of
  3203.                PERMS specifies the permissions of the newly
  3204.                created file.  If PERMS is omitted, the default
  3205.                value is 0666, which allows read and write for
  3206.                all.  This default is reasonable: see umask.
  3207.  
  3208.        sysread FILEHANDLE,SCALAR,LENGTH,OFFSET
  3209.  
  3210.        sysread FILEHANDLE,SCALAR,LENGTH
  3211.                Attempts to read LENGTH bytes of data into
  3212.                variable SCALAR from the specified FILEHANDLE,
  3213.                using the system call read(2).  It bypasses stdio,
  3214.                so mixing this with other kinds of reads may cause
  3215.                confusion.  Returns the number of bytes actually
  3216.                read, or undef if there was an error.  SCALAR will
  3217.                be grown or shrunk to the length actually read.
  3218.                An OFFSET may be specified to place the read data
  3219.                at some other place than the beginning of the
  3220.                string.
  3221.  
  3222.        system LIST
  3223.                Does exactly the same thing as "exec LIST" except
  3224.                that a fork is done first, and the parent process
  3225.                waits for the child process to complete.  Note
  3226.                that argument processing varies depending on the
  3227.                number of arguments.  The return value is the exit
  3228.                status of the program as returned by the wait()
  3229.                call.  To get the actual exit value divide by 256.
  3230.                See also the exec entry elsewhere in this
  3231.                document.  This is NOT what you want to use to
  3232.                capture the output from a command, for that you
  3233.                should merely use backticks, as described in the
  3234.                section on `STRING` in the perlop manpage.
  3235.  
  3236.        syswrite FILEHANDLE,SCALAR,LENGTH,OFFSET
  3237.  
  3238.        syswrite FILEHANDLE,SCALAR,LENGTH
  3239.                Attempts to write LENGTH bytes of data from
  3240.                variable SCALAR to the specified FILEHANDLE, using
  3241.                the system call write(2).  It bypasses stdio, so
  3242.                mixing this with prints may cause confusion.
  3243.                Returns the number of bytes actually written, or
  3244.                undef if there was an error.  An OFFSET may be
  3245.                specified to get the write data from some other
  3246.                place than the beginning of the string.
  3247.  
  3248.        tell FILEHANDLE
  3249.  
  3250.        tell    Returns the current file position for FILEHANDLE.
  3251.                FILEHANDLE may be an expression whose value gives
  3252.                the name of the actual filehandle.  If FILEHANDLE
  3253.                is omitted, assumes the file last read.
  3254.  
  3255.        telldir DIRHANDLE
  3256.                Returns the current position of the readdir()
  3257.                routines on DIRHANDLE.  Value may be given to
  3258.                seekdir() to access a particular location in a
  3259.                directory.  Has the same caveats about possible
  3260.                directory compaction as the corresponding system
  3261.                library routine.
  3262.  
  3263.        tie VARIABLE,CLASSNAME,LIST
  3264.                This function binds a variable to a package class
  3265.                that will provide the implementation for the
  3266.                variable.  VARIABLE is the name of the variable to
  3267.                be enchanted.  CLASSNAME is the name of a class
  3268.                implementing objects of correct type.  Any
  3269.                additional arguments are passed to the "new"
  3270.                method of the class (meaning TIESCALAR, TIEARRAY,
  3271.                or TIEHASH).  Typically these are arguments such
  3272.                as might be passed to the dbm_open() function of
  3273.                C.  The object returned by the "new" method is
  3274.                also returned by the tie() function, which would
  3275.                be useful if you want to access other methods in
  3276.                CLASSNAME.
  3277.  
  3278.                Note that functions such as keys() and values()
  3279.                may return huge array values when used on large
  3280.                objects, like DBM files.  You may prefer to use
  3281.                the each() function to iterate over such.
  3282.                Example:
  3283.  
  3284.                    # print out history file offsets
  3285.                    use NDBM_File;
  3286.                    tie(%HIST, NDBM_File, '/usr/lib/news/history', 1, 0);
  3287.                    while (($key,$val) = each %HIST) {
  3288.                        print $key, ' = ', unpack('L',$val), "\n";
  3289.                    }
  3290.                    untie(%HIST);
  3291.  
  3292.                A class implementing an associative array should
  3293.                have the following methods:
  3294.  
  3295.                    TIEHASH classname, LIST
  3296.                    DESTROY this
  3297.                    FETCH this, key
  3298.                    STORE this, key, value
  3299.                    DELETE this, key
  3300.                    EXISTS this, key
  3301.                    FIRSTKEY this
  3302.                    NEXTKEY this, lastkey
  3303.  
  3304.                A class implementing an ordinary array should have
  3305.                the following methods:
  3306.  
  3307.                    TIEARRAY classname, LIST
  3308.                    DESTROY this
  3309.                    FETCH this, key
  3310.                    STORE this, key, value
  3311.                    [others TBD]
  3312.  
  3313.                A class implementing a scalar should have the
  3314.                following methods:
  3315.  
  3316.                    TIESCALAR classname, LIST
  3317.                    DESTROY this
  3318.                    FETCH this,
  3319.                    STORE this, value
  3320.  
  3321.                Unlike dbmopen(), the tie() function will not use
  3322.                or require a module for you--you need to do that
  3323.                explicitly yourself.  See the DB_File manpage or
  3324.                the Config module for interesting tie()
  3325.                implementations.
  3326.  
  3327.        tied VARIABLE
  3328.                Returns a reference to the object underlying
  3329.                VARIABLE (the same value that was originally
  3330.                returned by the tie() call which bound the
  3331.                variable to a package.)  Returns the undefined
  3332.                value if VARIABLE isn't tied to a package.
  3333.  
  3334.        time    Returns the number of non-leap seconds since
  3335.                00:00:00 UTC, January 1, 1970.  Suitable for
  3336.                feeding to gmtime() and localtime().
  3337.  
  3338.        times   Returns a four-element array giving the user and
  3339.                system times, in seconds, for this process and the
  3340.                children of this process.
  3341.  
  3342.                    ($user,$system,$cuser,$csystem) = times;
  3343.  
  3344.        tr///   The translation operator.  See the perlop manpage.
  3345.  
  3346.        truncate FILEHANDLE,LENGTH
  3347.  
  3348.        truncate EXPR,LENGTH
  3349.                Truncates the file opened on FILEHANDLE, or named
  3350.                by EXPR, to the specified length.  Produces a
  3351.                fatal error if truncate isn't implemented on your
  3352.                system.
  3353.  
  3354.        uc EXPR Returns an uppercased version of EXPR.  This is
  3355.                the internal function implementing the \U escape
  3356.                in double-quoted strings.  Should respect any
  3357.                POSIX setlocale() settings.
  3358.  
  3359.        ucfirst EXPR
  3360.                Returns the value of EXPR with the first character
  3361.                uppercased.  This is the internal function
  3362.                implementing the \u escape in double-quoted
  3363.                strings.  Should respect any POSIX setlocale()
  3364.                settings.
  3365.  
  3366.        umask EXPR
  3367.  
  3368.        umask   Sets the umask for the process and returns the old
  3369.                one.  If EXPR is omitted, merely returns current
  3370.                umask.
  3371.  
  3372.        undef EXPR
  3373.  
  3374.        undef   Undefines the value of EXPR, which must be an
  3375.                lvalue.  Use only on a scalar value, an entire
  3376.                array, or a subroutine name (using "&").  (Using
  3377.                undef() will probably not do what you expect on
  3378.                most predefined variables or DBM list values, so
  3379.                don't do that.)  Always returns the undefined
  3380.                value.  You can omit the EXPR, in which case
  3381.                nothing is undefined, but you still get an
  3382.                undefined value that you could, for instance,
  3383.                return from a subroutine.  Examples:
  3384.  
  3385.                    undef $foo;
  3386.                    undef $bar{'blurfl'};
  3387.                    undef @ary;
  3388.                    undef %assoc;
  3389.                    undef &mysub;
  3390.                    return (wantarray ? () : undef) if $they_blew_it;
  3391.        unlink LIST
  3392.                Deletes a list of files.  Returns the number of
  3393.                files successfully deleted.
  3394.  
  3395.                    $cnt = unlink 'a', 'b', 'c';
  3396.                    unlink @goners;
  3397.                    unlink <*.bak>;
  3398.  
  3399.                Note: unlink will not delete directories unless
  3400.                you are superuser and the -U flag is supplied to
  3401.                Perl.  Even if these conditions are met, be warned
  3402.                that unlinking a directory can inflict damage on
  3403.                your filesystem.  Use rmdir instead.
  3404.  
  3405.        unpack TEMPLATE,EXPR
  3406.                Unpack does the reverse of pack: it takes a string
  3407.                representing a structure and expands it out into a
  3408.                list value, returning the array value.  (In a
  3409.                scalar context, it merely returns the first value
  3410.                produced.)  The TEMPLATE has the same format as in
  3411.                the pack function.  Here's a subroutine that does
  3412.                substring:
  3413.  
  3414.                    sub substr {
  3415.                        local($what,$where,$howmuch) = @_;
  3416.                        unpack("x$where a$howmuch", $what);
  3417.                    }
  3418.  
  3419.                and then there's
  3420.  
  3421.                    sub ordinal { unpack("c",$_[0]); } # same as ord()
  3422.  
  3423.                In addition, you may prefix a field with a
  3424.                %<number> to indicate that you want a <number>-bit
  3425.                checksum of the items instead of the items
  3426.                themselves.  Default is a 16-bit checksum.  For
  3427.                example, the following computes the same number as
  3428.                the System V sum program:
  3429.  
  3430.                    while (<>) {
  3431.                        $checksum += unpack("%16C*", $_);
  3432.                    }
  3433.                    $checksum %= 65536;
  3434.  
  3435.                The following efficiently counts the number of set
  3436.                bits in a bit vector:
  3437.  
  3438.                    $setbits = unpack("%32b*", $selectmask);
  3439.  
  3440.        untie VARIABLE
  3441.                Breaks the binding between a variable and a
  3442.                package.  (See tie().)
  3443.  
  3444.        unshift ARRAY,LIST
  3445.                Does the opposite of a shift.  Or the opposite of
  3446.                a push, depending on how you look at it.  Prepends
  3447.                list to the front of the array, and returns the
  3448.                new number of elements in the array.
  3449.  
  3450.                    unshift(ARGV, '-e') unless $ARGV[0] =~ /^-/;
  3451.  
  3452.                Note the LIST is prepended whole, not one element
  3453.                at a time, so the prepended elements stay in the
  3454.                same order.  Use reverse to do the reverse.
  3455.  
  3456.        use Module LIST
  3457.  
  3458.        use Module
  3459.                Imports some semantics into the current package
  3460.                from the named module, generally by aliasing
  3461.                certain subroutine or variable names into your
  3462.                package.  It is exactly equivalent to
  3463.  
  3464.                    BEGIN { require Module; import Module LIST; }
  3465.  
  3466.                The BEGIN forces the require and import to happen
  3467.                at compile time.  The require makes sure the
  3468.                module is loaded into memory if it hasn't been
  3469.                yet.  The import is not a builtin--it's just an
  3470.                ordinary static method call into the "Module"
  3471.                package to tell the module to import the list of
  3472.                features back into the current package.  The
  3473.                module can implement its import method any way it
  3474.                likes, though most modules just choose to derive
  3475.                their import method via inheritance from the
  3476.                Exporter class that is defined in the Exporter
  3477.                module. See the Exporter manpage.
  3478.  
  3479.                If you don't want your namespace altered,
  3480.                explicitly supply an empty list:
  3481.  
  3482.                    use Module ();
  3483.  
  3484.                That is exactly equivalent to
  3485.  
  3486.                    BEGIN { require Module; }
  3487.  
  3488.                Because this is a wide-open interface, pragmas
  3489.                (compiler directives) are also implemented this
  3490.                way.  Currently implemented pragmas are:
  3491.  
  3492.                    use integer;
  3493.                    use diagnostics;
  3494.                    use sigtrap qw(SEGV BUS);
  3495.                    use strict  qw(subs vars refs);
  3496.                    use subs    qw(afunc blurfl);
  3497.  
  3498.                These pseudomodules import semantics into the
  3499.                current block scope, unlike ordinary modules,
  3500.                which import symbols into the current package
  3501.                (which are effective through the end of the file).
  3502.  
  3503.                There's a corresponding "no" command that
  3504.                unimports meanings imported by use.
  3505.  
  3506.                    no integer;
  3507.                    no strict 'refs';
  3508.  
  3509.                See the perlmod manpage for a list of standard
  3510.                modules and pragmas.
  3511.  
  3512.        utime LIST
  3513.                Changes the access and modification times on each
  3514.                file of a list of files.  The first two elements
  3515.                of the list must be the NUMERICAL access and
  3516.                modification times, in that order.  Returns the
  3517.                number of files successfully changed.  The inode
  3518.                modification time of each file is set to the
  3519.                current time.  Example of a "touch" command:
  3520.  
  3521.                    #!/usr/bin/perl
  3522.                    $now = time;
  3523.                    utime $now, $now, @ARGV;
  3524.  
  3525.        values ASSOC_ARRAY
  3526.                Returns a normal array consisting of all the
  3527.                values of the named associative array.  (In a
  3528.                scalar context, returns the number of values.)
  3529.                The values are returned in an apparently random
  3530.                order, but it is the same order as either the
  3531.                keys() or each() function would produce on the
  3532.                same array.  See also keys(), each(), and sort().
  3533.  
  3534.        vec EXPR,OFFSET,BITS
  3535.                Treats the string in EXPR as a vector of unsigned
  3536.                integers, and returns the value of the bitfield
  3537.                specified by OFFSET.  BITS specifies the number of
  3538.                bits that are reserved for each entry in the bit
  3539.                vector. This must be a power of two from 1 to 32.
  3540.                vec() may also be assigned to, in which case
  3541.                parens are needed to give the expression the
  3542.                correct precedence as in
  3543.  
  3544.                    vec($image, $max_x * $x + $y, 8) = 3;
  3545.  
  3546.                Vectors created with vec() can also be manipulated
  3547.                with the logical operators |, & and ^, which will
  3548.                assume a bit vector operation is desired when both
  3549.                operands are strings.
  3550.  
  3551.                To transform a bit vector into a string or array
  3552.                of 0's and 1's, use these:
  3553.  
  3554.                    $bits = unpack("b*", $vector);
  3555.                    @bits = split(//, unpack("b*", $vector));
  3556.  
  3557.                If you know the exact length in bits, it can be
  3558.                used in place of the *.
  3559.  
  3560.        wait    Waits for a child process to terminate and returns
  3561.                the pid of the deceased process, or -1 if there
  3562.                are no child processes.  The status is returned in
  3563.                $?.
  3564.  
  3565.        waitpid PID,FLAGS
  3566.                Waits for a particular child process to terminate
  3567.                and returns the pid of the deceased process, or -1
  3568.                if there is no such child process.  The status is
  3569.                returned in $?.  If you say
  3570.  
  3571.                    use POSIX "wait_h";
  3572.                    ...
  3573.                    waitpid(-1,&WNOHANG);
  3574.  
  3575.                then you can do a non-blocking wait for any
  3576.                process.  Non-blocking wait is only available on
  3577.                machines supporting either the waitpid(2) or
  3578.                wait4(2) system calls.  However, waiting for a
  3579.                particular pid with FLAGS of 0 is implemented
  3580.                everywhere.  (Perl emulates the system call by
  3581.                remembering the status values of processes that
  3582.                have exited but have not been harvested by the
  3583.                Perl script yet.)
  3584.  
  3585.        wantarray
  3586.                Returns TRUE if the context of the currently
  3587.                executing subroutine is looking for a list value.
  3588.                Returns FALSE if the context is looking for a
  3589.                scalar.
  3590.  
  3591.                    return wantarray ? () : undef;
  3592.  
  3593.        warn LIST
  3594.                Produces a message on STDERR just like die(), but
  3595.                doesn't exit or on an exception.
  3596.  
  3597.        write FILEHANDLE
  3598.  
  3599.        write EXPR
  3600.  
  3601.        write   Writes a formatted record (possibly multi-line) to
  3602.                the specified file, using the format associated
  3603.                with that file.  By default the format for a file
  3604.                is the one having the same name is the filehandle,
  3605.                but the format for the current output channel (see
  3606.                the select() function) may be set explicitly by
  3607.                assigning the name of the format to the $~
  3608.                variable.
  3609.  
  3610.                Top of form processing is handled automatically:
  3611.                if there is insufficient room on the current page
  3612.                for the formatted record, the page is advanced by
  3613.                writing a form feed, a special top-of-page format
  3614.                is used to format the new page header, and then
  3615.                the record is written.  By default the top-of-page
  3616.                format is the name of the filehandle with "_TOP"
  3617.                appended, but it may be dynamically set to the
  3618.                format of your choice by assigning the name to the
  3619.                $^ variable while the filehandle is selected.  The
  3620.                number of lines remaining on the current page is
  3621.                in variable $-, which can be set to 0 to force a
  3622.                new page.
  3623.  
  3624.                If FILEHANDLE is unspecified, output goes to the
  3625.                current default output channel, which starts out
  3626.                as STDOUT but may be changed by the select
  3627.                operator.  If the FILEHANDLE is an EXPR, then the
  3628.                expression is evaluated and the resulting string
  3629.                is used to look up the name of the FILEHANDLE at
  3630.                run time.  For more on formats, see the perlform
  3631.                manpage.
  3632.  
  3633.                Note that write is NOT the opposite of read.
  3634.                Unfortunately.
  3635.  
  3636.        y///    The translation operator.  See the perlop manpage.
  3637.